Changeset View
Changeset View
Standalone View
Standalone View
src/httprpc.cpp
Show First 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | static bool checkCORS(Config &config, HTTPRequest *req) { | ||||
// 4. If the list of exposed headers is not empty add one or more | // 4. If the list of exposed headers is not empty add one or more | ||||
// Access-Control-Expose-Headers headers, with as values the header | // Access-Control-Expose-Headers headers, with as values the header | ||||
// field names given in the list of exposed headers. | // field names given in the list of exposed headers. | ||||
req->WriteHeader("Access-Control-Expose-Headers", "WWW-Authenticate"); | req->WriteHeader("Access-Control-Expose-Headers", "WWW-Authenticate"); | ||||
return false; | return false; | ||||
} | } | ||||
static bool HTTPReq_JSONRPC(Config &config, HTTPRequest *req, | bool HTTPRPCRequestProcessor::ProcessHTTPRequest(HTTPRequest *req) { | ||||
const std::string &) { | |||||
// First, check and/or set CORS headers | // First, check and/or set CORS headers | ||||
if (checkCORS(config, req)) { | if (checkCORS(config, req)) { | ||||
return true; | return true; | ||||
} | } | ||||
// JSONRPC handles only POST | // JSONRPC handles only POST | ||||
if (req->GetRequestMethod() != HTTPRequest::POST) { | if (req->GetRequestMethod() != HTTPRequest::POST) { | ||||
req->WriteReply(HTTP_BAD_METHOD, | req->WriteReply(HTTP_BAD_METHOD, | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | if (gArgs.GetArg("-rpcpassword", "") == "") { | ||||
config.SetRPCUserAndPassword(gArgs.GetArg("-rpcuser", "") + ":" + | config.SetRPCUserAndPassword(gArgs.GetArg("-rpcuser", "") + ":" + | ||||
gArgs.GetArg("-rpcpassword", "")); | gArgs.GetArg("-rpcpassword", "")); | ||||
} | } | ||||
config.SetRPCCORSDomain(gArgs.GetArg("-rpccorsdomain", "")); | config.SetRPCCORSDomain(gArgs.GetArg("-rpccorsdomain", "")); | ||||
return true; | return true; | ||||
} | } | ||||
bool StartHTTPRPC(Config &config) { | bool StartHTTPRPC(Config &config, | ||||
HTTPRPCRequestProcessor &httpRPCRequestProcessor) { | |||||
LogPrint(BCLog::RPC, "Starting HTTP RPC server\n"); | LogPrint(BCLog::RPC, "Starting HTTP RPC server\n"); | ||||
if (!InitRPCAuthentication(config)) return false; | if (!InitRPCAuthentication(config)) return false; | ||||
RegisterHTTPHandler("/", true, HTTPReq_JSONRPC); | const std::function<bool(Config &, HTTPRequest *, const std::string &)> | ||||
&rpcFunction = | |||||
std::bind(&HTTPRPCRequestProcessor::DelegateHTTPRequest, | |||||
&httpRPCRequestProcessor, std::placeholders::_2); | |||||
RegisterHTTPHandler("/", true, rpcFunction); | |||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
// ifdef can be removed once we switch to better endpoint support and API | // ifdef can be removed once we switch to better endpoint support and API | ||||
// versioning | // versioning | ||||
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC); | RegisterHTTPHandler("/wallet/", false, rpcFunction); | ||||
#endif | #endif | ||||
assert(EventBase()); | assert(EventBase()); | ||||
httpRPCTimerInterface = new HTTPRPCTimerInterface(EventBase()); | httpRPCTimerInterface = new HTTPRPCTimerInterface(EventBase()); | ||||
RPCSetTimerInterface(httpRPCTimerInterface); | RPCSetTimerInterface(httpRPCTimerInterface); | ||||
return true; | return true; | ||||
} | } | ||||
void InterruptHTTPRPC() { | void InterruptHTTPRPC() { | ||||
Show All 12 Lines |