HttpRequest: missing fields initializations
* Some fields weren't initialized, leading to random crashes later on * Remove the enum that was used for protocol options * Use a single field to track the request state, instead of separate booleans.
This commit is contained in:
@@ -84,11 +84,17 @@ private:
|
|||||||
BHttpAuthentication fAuthentication;
|
BHttpAuthentication fAuthentication;
|
||||||
|
|
||||||
// Request status
|
// Request status
|
||||||
|
|
||||||
BHttpHeaders fOutputHeaders;
|
BHttpHeaders fOutputHeaders;
|
||||||
bool fStatusReceived;
|
|
||||||
bool fHeadersReceived;
|
// Request state/events
|
||||||
bool fContentReceived;
|
enum {
|
||||||
bool fTrailingHeadersReceived;
|
kRequestInitialState,
|
||||||
|
kRequestStatusReceived,
|
||||||
|
kRequestHeadersReceived,
|
||||||
|
kRequestContentReceived,
|
||||||
|
kRequestTrailingHeadersReceived
|
||||||
|
} fRequestStatus;
|
||||||
|
|
||||||
|
|
||||||
// Protocol options
|
// Protocol options
|
||||||
@@ -134,43 +140,6 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// HTTP Protocol options
|
|
||||||
enum {
|
|
||||||
B_HTTPOPT_METHOD = 0,
|
|
||||||
// (int) Request method (see B_HTTP_GET, ...)
|
|
||||||
B_HTTPOPT_FOLLOWLOCATION,
|
|
||||||
// (bool) Follow Location: headers
|
|
||||||
B_HTTPOPT_MAXREDIRS,
|
|
||||||
// (int) Max relocation
|
|
||||||
B_HTTPOPT_HEADERS,
|
|
||||||
// (BHttpHeaders*) Headers to be sent
|
|
||||||
B_HTTPOPT_REFERER,
|
|
||||||
// (string) Referer
|
|
||||||
B_HTTPOPT_USERAGENT,
|
|
||||||
// (string) User-Agent
|
|
||||||
B_HTTPOPT_SETCOOKIES,
|
|
||||||
// (bool) Send cookies from context
|
|
||||||
B_HTTPOPT_DISCARD_DATA,
|
|
||||||
// (bool) Discard incoming data (still notified)
|
|
||||||
B_HTTPOPT_DISABLE_LISTENER,
|
|
||||||
// (bool) Don't send notification to the listener
|
|
||||||
B_HTTPOPT_AUTOREFERER,
|
|
||||||
// (bool) Automatically set the Referer header
|
|
||||||
B_HTTPOPT_POSTFIELDS,
|
|
||||||
// (BHttpForm*) POST data to be sent
|
|
||||||
B_HTTPOPT_INPUTDATA,
|
|
||||||
// (BDataIO*) Input data to be sent (POST, PUT)
|
|
||||||
B_HTTPOPT_AUTHUSERNAME,
|
|
||||||
// (string) Authentication username
|
|
||||||
B_HTTPOPT_AUTHPASSWORD,
|
|
||||||
// (string) Authentication password
|
|
||||||
B_HTTPOPT_AUTHMETHOD,
|
|
||||||
// (int) Allowed authentication methods (see BHttpAuthenticationMethod)
|
|
||||||
|
|
||||||
B_HTTPOPT__OPT_NUM
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// HTTP status classes
|
// HTTP status classes
|
||||||
enum http_status_code_class {
|
enum http_status_code_class {
|
||||||
B_HTTP_STATUS_CLASS_INVALID = 000,
|
B_HTTP_STATUS_CLASS_INVALID = 000,
|
||||||
|
|||||||
@@ -33,9 +33,14 @@ BHttpRequest::BHttpRequest(const BUrl& url, BUrlResult& result, bool ssl,
|
|||||||
BUrlContext* context)
|
BUrlContext* context)
|
||||||
:
|
:
|
||||||
BUrlRequest(url, listener, context, result, "BUrlProtocol.HTTP", protocolName),
|
BUrlRequest(url, listener, context, result, "BUrlProtocol.HTTP", protocolName),
|
||||||
|
fSocket(NULL),
|
||||||
fSSL(ssl),
|
fSSL(ssl),
|
||||||
fRequestMethod(B_HTTP_GET),
|
fRequestMethod(B_HTTP_GET),
|
||||||
fHttpVersion(B_HTTP_11)
|
fHttpVersion(B_HTTP_11),
|
||||||
|
fRequestStatus(kRequestInitialState),
|
||||||
|
fOptHeaders(NULL),
|
||||||
|
fOptInputData(NULL),
|
||||||
|
fOptInputDataSize(-1)
|
||||||
{
|
{
|
||||||
_ResetOptions();
|
_ResetOptions();
|
||||||
if (ssl)
|
if (ssl)
|
||||||
@@ -488,8 +493,7 @@ BHttpRequest::_MakeRequest()
|
|||||||
}
|
}
|
||||||
fOutputBuffer.Truncate(0, true);
|
fOutputBuffer.Truncate(0, true);
|
||||||
|
|
||||||
fStatusReceived = false;
|
fRequestStatus = kRequestInitialState;
|
||||||
fHeadersReceived = false;
|
|
||||||
|
|
||||||
// Receive loop
|
// Receive loop
|
||||||
bool receiveEnd = false;
|
bool receiveEnd = false;
|
||||||
@@ -522,16 +526,16 @@ BHttpRequest::_MakeRequest()
|
|||||||
else
|
else
|
||||||
bytesRead = 0;
|
bytesRead = 0;
|
||||||
|
|
||||||
if (!fStatusReceived) {
|
if (fRequestStatus < kRequestStatusReceived) {
|
||||||
_ParseStatus();
|
_ParseStatus();
|
||||||
|
|
||||||
//! ProtocolHook:ResponseStarted
|
//! ProtocolHook:ResponseStarted
|
||||||
if (fStatusReceived && fListener != NULL)
|
if (fRequestStatus >= kRequestStatusReceived && fListener != NULL)
|
||||||
fListener->ResponseStarted(this);
|
fListener->ResponseStarted(this);
|
||||||
} else if (!fHeadersReceived) {
|
} else if (fRequestStatus < kRequestHeadersReceived) {
|
||||||
_ParseHeaders();
|
_ParseHeaders();
|
||||||
|
|
||||||
if (fHeadersReceived) {
|
if (fRequestStatus >= kRequestHeadersReceived) {
|
||||||
receiveBufferSize = kHttpProtocolReceiveBufferSize;
|
receiveBufferSize = kHttpProtocolReceiveBufferSize;
|
||||||
_ResultHeaders() = fHeaders;
|
_ResultHeaders() = fHeaders;
|
||||||
|
|
||||||
@@ -595,7 +599,7 @@ BHttpRequest::_MakeRequest()
|
|||||||
PRINT(("BHP[%p] Chunk %s=%ld\n", this,
|
PRINT(("BHP[%p] Chunk %s=%ld\n", this,
|
||||||
chunkHeader.String(), chunkSize));
|
chunkHeader.String(), chunkSize));
|
||||||
if (chunkSize == 0) {
|
if (chunkSize == 0) {
|
||||||
fContentReceived = true;
|
fRequestStatus = kRequestContentReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesRead = -1;
|
bytesRead = -1;
|
||||||
@@ -697,7 +701,7 @@ BHttpRequest::_ParseStatus()
|
|||||||
if (statusLine.CountChars() < 12)
|
if (statusLine.CountChars() < 12)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fStatusReceived = true;
|
fRequestStatus = kRequestStatusReceived;
|
||||||
|
|
||||||
BString statusCodeStr;
|
BString statusCodeStr;
|
||||||
BString statusText;
|
BString statusText;
|
||||||
@@ -720,7 +724,7 @@ BHttpRequest::_ParseHeaders()
|
|||||||
|
|
||||||
// An empty line means the end of the header section
|
// An empty line means the end of the header section
|
||||||
if (currentHeader.Length() == 0) {
|
if (currentHeader.Length() == 0) {
|
||||||
fHeadersReceived = true;
|
fRequestStatus = kRequestHeadersReceived;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user