diff options
| author | Wladimir J. van der Laan <[email protected]> | 2014-08-07 10:39:19 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2014-08-07 10:50:37 +0200 |
| commit | 0b588168ab24c1db93fd568cc136380b59fc5809 (patch) | |
| tree | 8e1fbb72c7d1a7774706671eef0baf08f11de9e4 /src/rpcprotocol.cpp | |
| parent | Merge pull request #4498 (diff) | |
| parent | Remove size limit in RPC client, keep it in server (diff) | |
| download | discoin-0b588168ab24c1db93fd568cc136380b59fc5809.tar.xz discoin-0b588168ab24c1db93fd568cc136380b59fc5809.zip | |
Merge pull request #4640
733177e Remove size limit in RPC client, keep it in server (Wladimir J. van der Laan)
e17151a Avoid a copy in RPC output (Wladimir J. van der Laan)
Diffstat (limited to 'src/rpcprotocol.cpp')
| -rw-r--r-- | src/rpcprotocol.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/rpcprotocol.cpp b/src/rpcprotocol.cpp index 9e18ca847..643208b3b 100644 --- a/src/rpcprotocol.cpp +++ b/src/rpcprotocol.cpp @@ -93,8 +93,7 @@ string HTTPError(int nStatus, bool keepalive, bool headersOnly) headersOnly, "text/plain"); } -string HTTPReply(int nStatus, const string& strMsg, bool keepalive, - bool headersOnly, const char *contentType) +string HTTPReplyHeader(int nStatus, bool keepalive, size_t contentLength, const char *contentType) { return strprintf( "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-Type: %s\r\n" "Server: bitcoin-json-rpc/%s\r\n" - "\r\n" - "%s", + "\r\n", nStatus, httpStatusDescription(nStatus), rfc1123Time(), keepalive ? "keep-alive" : "close", - (headersOnly ? 0 : strMsg.size()), + contentLength, contentType, - FormatFullVersion(), - (headersOnly ? "" : strMsg.c_str()) - ); + FormatFullVersion()); +} + +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, @@ -194,14 +201,14 @@ int ReadHTTPHeaders(std::basic_istream<char>& stream, map<string, string>& mapHe int ReadHTTPMessage(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet, string& strMessageRet, - int nProto) + int nProto, size_t max_size) { mapHeadersRet.clear(); strMessageRet = ""; // Read header 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; // Read message |