From 86d778125540c99374960eacf075ce07a3471505 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 29 Dec 2012 14:41:07 -0800 Subject: [PATCH] Fix user agent for JSON-RPC to use SYSTEM_NAME. --- src/cpp/ripple/rpc.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cpp/ripple/rpc.cpp b/src/cpp/ripple/rpc.cpp index 8d7c84391f..97731b7631 100644 --- a/src/cpp/ripple/rpc.cpp +++ b/src/cpp/ripple/rpc.cpp @@ -25,12 +25,13 @@ using namespace boost::asio; Json::Value JSONRPCError(int code, const std::string& message) { Json::Value error(Json::objectValue); - error["code"]=Json::Value(code); - error["message"]=Json::Value(message); + + error["code"] = Json::Value(code); + error["message"] = Json::Value(message); + return error; } - // // HTTP protocol // @@ -41,16 +42,19 @@ Json::Value JSONRPCError(int code, const std::string& message) std::string createHTTPPost(const std::string& strMsg, const std::map& mapRequestHeaders) { std::ostringstream s; + s << "POST / HTTP/1.1\r\n" - << "User-Agent: coin-json-rpc/" << FormatFullVersion() << "\r\n" + << "User-Agent: " SYSTEM_NAME "-json-rpc/" << FormatFullVersion() << "\r\n" << "Host: 127.0.0.1\r\n" << "Content-Type: application/json\r\n" << "Content-Length: " << strMsg.size() << "\r\n" << "Accept: application/json\r\n"; typedef std::map::value_type HeaderType; + BOOST_FOREACH(const HeaderType& item, mapRequestHeaders) s << item.first << ": " << item.second << "\r\n"; + s << "\r\n" << strMsg; return s.str(); @@ -76,7 +80,7 @@ std::string HTTPReply(int nStatus, const std::string& strMsg) if (nStatus == 401) return strprintf("HTTP/1.0 401 Authorization Required\r\n" "Date: %s\r\n" - "Server: coin-json-rpc/%s\r\n" + "Server: " SYSTEM_NAME "-json-rpc/%s\r\n" "WWW-Authenticate: Basic realm=\"jsonrpc\"\r\n" "Content-Type: text/html\r\n" "Content-Length: 296\r\n" @@ -107,7 +111,7 @@ std::string HTTPReply(int nStatus, const std::string& strMsg) "%s" "Content-Length: %d\r\n" "Content-Type: application/json; charset=UTF-8\r\n" - "Server: coin-json-rpc/%s\r\n" + "Server: " SYSTEM_NAME "-json-rpc/%s\r\n" "\r\n" "%s\r\n", nStatus, @@ -116,7 +120,7 @@ std::string HTTPReply(int nStatus, const std::string& strMsg) access.c_str(), strMsg.size() + 2, SERVER_VERSION, - strMsg.c_str()); + strMsg.c_str()); } int ReadHTTPStatus(std::basic_istream& stream) @@ -180,7 +184,6 @@ int ReadHTTP(std::basic_istream& stream, std::map& mapHeaders) { @@ -253,3 +257,5 @@ void ErrorReply(std::ostream& stream, const Json::Value& objError, const Json::V std::string strReply = JSONRPCReply(Json::Value(), objError, id); stream << HTTPReply(nStatus, strReply) << std::flush; } + +// vim:ts=4