Xojo.Net.HTTPSocket event sequence for HeadersReceived and PageReceived

I’m working on some HTTPSocket stuff (REST API related) and I need to process the headers together with the content.
From the Xojo manual:
The HeadersReceived event is called when headers are received from the server.
The PageReceived event is called when a new page has been retrieved from the server as a result of calling Send.

My question is:
Are we guaranteed that the HeadersReceived event fires before the PageReceived event?
If not, is the best way to fire a xojo.core.timer.CallLater with a delay and then check if the other event has already been received?
Or would you do it another way, and why?

Well, in theory the headers have to be received before the page, and usually the page data is larger than the header data (but not always)… The HeadersReceived event should fire before the PageReceived event, but I think the official line from Xojo is something about events can be fired at any time and in any order…

I would either do a lot of testing to ensure that events are firing in order, or throw a flag to keep track of which event you received and then do what you need to do…

You can read the headers relating to that response inside the PageReceived by accessing ResponseHeader. I would do it this way, then you can access the page content and headers at the same time without using other methods of state management to link the two on the off chance that two headers are returned before a PageReceived is triggered.

I would only use the HeadersReceived event if you want to do something specific with those headers before working on or ignoring the page content.

That’s what I was doing, but then I started fearing that I might be accessing headers that hadn’t arrived yet.
And of course if I process the page and the headers aren’t there yet, I can’t do it again because the PageReceived for this call will only happen once. Hence my question.

It would be very easy if I can rely on the headers already being there in the PageReceived event (counting on the fact that HeadersReceived fires before PageReceived). If I can’t rely on that, not so easy.

Wish I knew for certain.

Headers are sent before the page (as part of the HTTP response)
They literally HAVE to arrive before the page

[quote=330251:@Norman Palardy]Headers are sent before the page (as part of the HTTP response)
They literally HAVE to arrive before the page[/quote]
Thank you for confirming. It seemed logical, but I wasn’t 100% sure.