зеркало из https://github.com/mozilla/pjs.git
144288 - r=sgehani sr=dveditz
make libxpnet understand http response codes
This commit is contained in:
Родитель
2158d7ffee
Коммит
9a31b7a3d0
|
@ -91,7 +91,8 @@ nsHTTPConn::nsHTTPConn(char *aURL, int (*aEventPumpCB)(void)) :
|
|||
mProxyPswd(NULL),
|
||||
mDestFile(NULL),
|
||||
mHostPathAllocd(FALSE),
|
||||
mSocket(NULL)
|
||||
mSocket(NULL),
|
||||
mResponseCode(0)
|
||||
{
|
||||
// parse URL
|
||||
if (ParseURL(kHTTPProto, aURL, &mHost, &mPort, &mPath) == OK)
|
||||
|
@ -115,7 +116,8 @@ nsHTTPConn::nsHTTPConn(char *aURL) :
|
|||
mProxyPswd(NULL),
|
||||
mDestFile(NULL),
|
||||
mHostPathAllocd(FALSE),
|
||||
mSocket(NULL)
|
||||
mSocket(NULL),
|
||||
mResponseCode(0)
|
||||
{
|
||||
// parse URL
|
||||
if (ParseURL(kHTTPProto, aURL, &mHost, &mPort, &mPath) == OK)
|
||||
|
@ -412,6 +414,16 @@ nsHTTPConn::Response(HTTPGetCB aCallback, char *aDestFile, int aResumePos)
|
|||
}
|
||||
else
|
||||
{
|
||||
ParseResponseCode((const char *)resp, &mResponseCode);
|
||||
|
||||
if ( mResponseCode < 200 || mResponseCode >=300 )
|
||||
{
|
||||
// if we don't get a response code in the 200 range then fail
|
||||
// TODO: handle the response codes in the 300 range
|
||||
rv = nsHTTPConn::E_HTTP_RESPONSE;
|
||||
break;
|
||||
}
|
||||
|
||||
ParseContentLength((const char *)resp, &expectedSize);
|
||||
|
||||
// move past hdr-body delimiter
|
||||
|
@ -443,7 +455,7 @@ nsHTTPConn::Response(HTTPGetCB aCallback, char *aDestFile, int aResumePos)
|
|||
|
||||
} while ( rv == nsSocket::E_READ_MORE || rv == nsSocket::OK);
|
||||
|
||||
if ( bytesWritten == expectedSize )
|
||||
if ( bytesWritten == expectedSize && rv != nsHTTPConn::E_HTTP_RESPONSE)
|
||||
rv = nsSocket::E_EOF_FOUND;
|
||||
|
||||
if (rv == nsSocket::E_EOF_FOUND)
|
||||
|
@ -546,6 +558,26 @@ nsHTTPConn::ParseURL(const char *aProto, char *aURL, char **aHost,
|
|||
return OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTTPConn::ParseResponseCode(const char *aBuf, int *aCode)
|
||||
{
|
||||
char codeStr[4];
|
||||
char *pos;
|
||||
|
||||
if (!aBuf || !aCode)
|
||||
return;
|
||||
|
||||
// make sure the beginning of the buffer is the HTTP status code
|
||||
if (strncmp(aBuf,"HTTP/",5) == 0)
|
||||
{
|
||||
pos = strstr(aBuf," "); // find the space before the code
|
||||
++pos; // move to the beginning of the code
|
||||
strncpy((char *)codeStr,pos, 3);
|
||||
codeStr[3] = '\0';
|
||||
*aCode = atoi(codeStr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsHTTPConn::ParseContentLength(const char *aBuf, int *aLength)
|
||||
{
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
int ResumeOrGet(HTTPGetCB aCallback, char *aDestFile);
|
||||
int Get(HTTPGetCB aCallback, char *aDestFile);
|
||||
int Get(HTTPGetCB aCallback, char *aDestFile, int aResumePos);
|
||||
|
||||
int GetResponseCode() { return mResponseCode; }
|
||||
int Close();
|
||||
|
||||
void SetProxyInfo(char *aProxiedURL, char *aProxyUser,
|
||||
|
@ -60,6 +60,7 @@ public:
|
|||
E_B64_ENCODE = -805,
|
||||
E_OPEN_FILE = -806,
|
||||
E_SEEK_FILE = -807,
|
||||
E_HTTP_RESPONSE = -808,
|
||||
E_USER_CANCEL = -813
|
||||
};
|
||||
|
||||
|
@ -67,6 +68,7 @@ private:
|
|||
int Request(int aResumePos);
|
||||
int Response(HTTPGetCB aCallback, char *aDestFile, int aResumePos);
|
||||
void ParseContentLength(const char *aBuf, int *aLength);
|
||||
void ParseResponseCode(const char *aBuf, int *aCode);
|
||||
int Base64Encode(const unsigned char *in_str, int in_len,
|
||||
char *out_str, int out_len);
|
||||
|
||||
|
@ -80,6 +82,7 @@ private:
|
|||
char *mDestFile;
|
||||
int mHostPathAllocd;
|
||||
nsSocket *mSocket;
|
||||
int mResponseCode;
|
||||
};
|
||||
|
||||
#ifndef NULL
|
||||
|
|
Загрузка…
Ссылка в новой задаче