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:
@@ -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++)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user