mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix user agent for JSON-RPC to use SYSTEM_NAME.
This commit is contained in:
@@ -25,12 +25,13 @@ using namespace boost::asio;
|
|||||||
Json::Value JSONRPCError(int code, const std::string& message)
|
Json::Value JSONRPCError(int code, const std::string& message)
|
||||||
{
|
{
|
||||||
Json::Value error(Json::objectValue);
|
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;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// HTTP protocol
|
// 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<std::string, std::string>& mapRequestHeaders)
|
std::string createHTTPPost(const std::string& strMsg, const std::map<std::string, std::string>& mapRequestHeaders)
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
|
||||||
s << "POST / HTTP/1.1\r\n"
|
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"
|
<< "Host: 127.0.0.1\r\n"
|
||||||
<< "Content-Type: application/json\r\n"
|
<< "Content-Type: application/json\r\n"
|
||||||
<< "Content-Length: " << strMsg.size() << "\r\n"
|
<< "Content-Length: " << strMsg.size() << "\r\n"
|
||||||
<< "Accept: application/json\r\n";
|
<< "Accept: application/json\r\n";
|
||||||
|
|
||||||
typedef std::map<std::string, std::string>::value_type HeaderType;
|
typedef std::map<std::string, std::string>::value_type HeaderType;
|
||||||
|
|
||||||
BOOST_FOREACH(const HeaderType& item, mapRequestHeaders)
|
BOOST_FOREACH(const HeaderType& item, mapRequestHeaders)
|
||||||
s << item.first << ": " << item.second << "\r\n";
|
s << item.first << ": " << item.second << "\r\n";
|
||||||
|
|
||||||
s << "\r\n" << strMsg;
|
s << "\r\n" << strMsg;
|
||||||
|
|
||||||
return s.str();
|
return s.str();
|
||||||
@@ -76,7 +80,7 @@ std::string HTTPReply(int nStatus, const std::string& strMsg)
|
|||||||
if (nStatus == 401)
|
if (nStatus == 401)
|
||||||
return strprintf("HTTP/1.0 401 Authorization Required\r\n"
|
return strprintf("HTTP/1.0 401 Authorization Required\r\n"
|
||||||
"Date: %s\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"
|
"WWW-Authenticate: Basic realm=\"jsonrpc\"\r\n"
|
||||||
"Content-Type: text/html\r\n"
|
"Content-Type: text/html\r\n"
|
||||||
"Content-Length: 296\r\n"
|
"Content-Length: 296\r\n"
|
||||||
@@ -107,7 +111,7 @@ std::string HTTPReply(int nStatus, const std::string& strMsg)
|
|||||||
"%s"
|
"%s"
|
||||||
"Content-Length: %d\r\n"
|
"Content-Length: %d\r\n"
|
||||||
"Content-Type: application/json; charset=UTF-8\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"
|
"\r\n"
|
||||||
"%s\r\n",
|
"%s\r\n",
|
||||||
nStatus,
|
nStatus,
|
||||||
@@ -180,7 +184,6 @@ int ReadHTTP(std::basic_istream<char>& stream, std::map<std::string, std::string
|
|||||||
return nStatus;
|
return nStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string DecodeBase64(std::string s)
|
std::string DecodeBase64(std::string s)
|
||||||
{ // FIXME: This performs badly
|
{ // FIXME: This performs badly
|
||||||
BIO *b64, *bmem;
|
BIO *b64, *bmem;
|
||||||
@@ -198,6 +201,7 @@ std::string DecodeBase64(std::string s)
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bool HTTPAuthorized(map<std::string, std::string>& mapHeaders)
|
bool HTTPAuthorized(map<std::string, std::string>& 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);
|
std::string strReply = JSONRPCReply(Json::Value(), objError, id);
|
||||||
stream << HTTPReply(nStatus, strReply) << std::flush;
|
stream << HTTPReply(nStatus, strReply) << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim:ts=4
|
||||||
|
|||||||
Reference in New Issue
Block a user