Move HeadersReceived hook after parsing of cookies

I still don't get what's happening, but doing the cookie parsing at the
same time as the main thread is handling HeadersReceived seems to
trigger a memory corruption, and it will escape all my attempts to debug
it (adding printfs or any other slight change to the code will make it
go away). So just chage the order we do things and hope that's enough to
always avoid it.

As a side effect, HeadersReceived can now rely on the cookies being
already stored in the cookie jar, which I think makes more sense.

I still plan to rewrite the HTTP request code as a proper state machine,
instead of one long Run() function. This would allow to run it in
smaller steps, and thus group multiple requests in a single thread
(triggering them from poll, select, or similar).
This commit is contained in:
Adrien Destugues
2017-12-07 22:45:44 +01:00
parent 0ba5f365d0
commit ed8f28a480
3 changed files with 12 additions and 7 deletions
@@ -296,6 +296,9 @@ BHttpHeaders::Clear()
BHttpHeaders&
BHttpHeaders::operator=(const BHttpHeaders& other)
{
if (&other == this)
return;
Clear();
for (int32 i = 0; i < other.CountHeaders(); i++)
+5 -4
View File
@@ -611,10 +611,6 @@ BHttpRequest::_MakeRequest()
if (fRequestStatus >= kRequestHeadersReceived) {
_ResultHeaders() = fHeaders;
//! ProtocolHook:HeadersReceived
if (fListener != NULL)
fListener->HeadersReceived(this, fResult);
// Parse received cookies
if (fContext != NULL) {
for (int32 i = 0; i < fHeaders.CountHeaders(); i++) {
@@ -625,6 +621,11 @@ BHttpRequest::_MakeRequest()
}
}
//! ProtocolHook:HeadersReceived
if (fListener != NULL)
fListener->HeadersReceived(this, fResult);
if (BString(fHeaders["Transfer-Encoding"]) == "chunked")
readByChunks = true;
+4 -3
View File
@@ -26,10 +26,11 @@ BHttpResult::BHttpResult(const BUrl& url)
BHttpResult::BHttpResult(BMessage* archive)
:
BUrlResult(archive)
BUrlResult(archive),
fUrl(archive->FindString("http:url")),
fHeaders(),
fStatusCode(archive->FindInt32("http:statusCode"))
{
fUrl = archive->FindString("http:url");
fStatusCode = archive->FindInt32("http:statusCode");
fStatusString = archive->FindString("http:statusString");
BMessage headers;