|
|
@ -93,8 +93,7 @@ string HTTPError(int nStatus, bool keepalive, bool headersOnly) |
|
|
|
headersOnly, "text/plain"); |
|
|
|
headersOnly, "text/plain"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string HTTPReply(int nStatus, const string& strMsg, bool keepalive, |
|
|
|
string HTTPReplyHeader(int nStatus, bool keepalive, size_t contentLength, const char *contentType) |
|
|
|
bool headersOnly, const char *contentType) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return strprintf( |
|
|
|
return strprintf( |
|
|
|
"HTTP/1.1 %d %s\r\n" |
|
|
|
"HTTP/1.1 %d %s\r\n" |
|
|
@ -103,17 +102,25 @@ string HTTPReply(int nStatus, const string& strMsg, bool keepalive, |
|
|
|
"Content-Length: %u\r\n" |
|
|
|
"Content-Length: %u\r\n" |
|
|
|
"Content-Type: %s\r\n" |
|
|
|
"Content-Type: %s\r\n" |
|
|
|
"Server: bitcoin-json-rpc/%s\r\n" |
|
|
|
"Server: bitcoin-json-rpc/%s\r\n" |
|
|
|
"\r\n" |
|
|
|
"\r\n", |
|
|
|
"%s", |
|
|
|
|
|
|
|
nStatus, |
|
|
|
nStatus, |
|
|
|
httpStatusDescription(nStatus), |
|
|
|
httpStatusDescription(nStatus), |
|
|
|
rfc1123Time(), |
|
|
|
rfc1123Time(), |
|
|
|
keepalive ? "keep-alive" : "close", |
|
|
|
keepalive ? "keep-alive" : "close", |
|
|
|
(headersOnly ? 0 : strMsg.size()), |
|
|
|
contentLength, |
|
|
|
contentType, |
|
|
|
contentType, |
|
|
|
FormatFullVersion(), |
|
|
|
FormatFullVersion()); |
|
|
|
(headersOnly ? "" : strMsg.c_str()) |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
string HTTPReply(int nStatus, const string& strMsg, bool keepalive, |
|
|
|
|
|
|
|
bool headersOnly, const char *contentType) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (headersOnly) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return HTTPReplyHeader(nStatus, keepalive, 0, contentType); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return HTTPReplyHeader(nStatus, keepalive, strMsg.size(), contentType) + strMsg; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ReadHTTPRequestLine(std::basic_istream<char>& stream, int &proto, |
|
|
|
bool ReadHTTPRequestLine(std::basic_istream<char>& stream, int &proto, |
|
|
@ -194,14 +201,14 @@ int ReadHTTPHeaders(std::basic_istream<char>& stream, map<string, string>& mapHe |
|
|
|
|
|
|
|
|
|
|
|
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string, |
|
|
|
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string, |
|
|
|
string>& mapHeadersRet, string& strMessageRet, |
|
|
|
string>& mapHeadersRet, string& strMessageRet, |
|
|
|
int nProto) |
|
|
|
int nProto, size_t max_size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mapHeadersRet.clear(); |
|
|
|
mapHeadersRet.clear(); |
|
|
|
strMessageRet = ""; |
|
|
|
strMessageRet = ""; |
|
|
|
|
|
|
|
|
|
|
|
// Read header
|
|
|
|
// Read header
|
|
|
|
int nLen = ReadHTTPHeaders(stream, mapHeadersRet); |
|
|
|
int nLen = ReadHTTPHeaders(stream, mapHeadersRet); |
|
|
|
if (nLen < 0 || nLen > (int)MAX_SIZE) |
|
|
|
if (nLen < 0 || (size_t)nLen > max_size) |
|
|
|
return HTTP_INTERNAL_SERVER_ERROR; |
|
|
|
return HTTP_INTERNAL_SERVER_ERROR; |
|
|
|
|
|
|
|
|
|
|
|
// Read message
|
|
|
|
// Read message
|
|
|
|