Merge pull request #5326
5dc713b
[REST] set REST API behind "-rest" option (Jonas Schnelli)78bdc81
[REST] give an appropriate response in warmup phase (Jonas Schnelli)210eba9
[REST] fix headersonly flag for BINARY responses (Jonas Schnelli)
This commit is contained in:
commit
108b19f7ef
5 changed files with 20 additions and 3 deletions
|
@ -352,6 +352,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||
|
||||
strUsage += "\n" + _("RPC server options:") + "\n";
|
||||
strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n";
|
||||
strUsage += " -rest " + strprintf(_("Accept public REST requests (default: %u)"), 0) + "\n";
|
||||
strUsage += " -rpcbind=<addr> " + _("Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6. This option can be specified multiple times (default: bind to all interfaces)") + "\n";
|
||||
strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n";
|
||||
strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n";
|
||||
|
|
|
@ -100,7 +100,7 @@ static bool rest_block(AcceptedConnection *conn,
|
|||
switch (rf) {
|
||||
case RF_BINARY: {
|
||||
string binaryBlock = ssBlock.str();
|
||||
conn->stream() << HTTPReply(HTTP_OK, binaryBlock, fRun, true, "application/octet-stream") << binaryBlock << std::flush;
|
||||
conn->stream() << HTTPReplyHeader(HTTP_OK, fRun, binaryBlock.size(), "application/octet-stream") << binaryBlock << std::flush;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ static bool rest_tx(AcceptedConnection *conn,
|
|||
switch (rf) {
|
||||
case RF_BINARY: {
|
||||
string binaryTx = ssTx.str();
|
||||
conn->stream() << HTTPReply(HTTP_OK, binaryTx, fRun, true, "application/octet-stream") << binaryTx << std::flush;
|
||||
conn->stream() << HTTPReplyHeader(HTTP_OK, fRun, binaryTx.size(), "application/octet-stream") << binaryTx << std::flush;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -188,6 +188,10 @@ bool HTTPReq_REST(AcceptedConnection *conn,
|
|||
bool fRun)
|
||||
{
|
||||
try {
|
||||
std::string statusmessage;
|
||||
if(RPCIsInWarmup(&statusmessage))
|
||||
throw RESTERR(HTTP_SERVICE_UNAVAILABLE, "Service temporarily unavailable: "+statusmessage);
|
||||
|
||||
for (unsigned int i = 0; i < ARRAYLEN(uri_prefixes); i++) {
|
||||
unsigned int plen = strlen(uri_prefixes[i].prefix);
|
||||
if (strURI.substr(0, plen) == uri_prefixes[i].prefix) {
|
||||
|
|
|
@ -28,6 +28,7 @@ enum HTTPStatusCode
|
|||
HTTP_FORBIDDEN = 403,
|
||||
HTTP_NOT_FOUND = 404,
|
||||
HTTP_INTERNAL_SERVER_ERROR = 500,
|
||||
HTTP_SERVICE_UNAVAILABLE = 503,
|
||||
};
|
||||
|
||||
//! Bitcoin RPC error codes
|
||||
|
|
|
@ -756,6 +756,14 @@ void SetRPCWarmupFinished()
|
|||
fRPCInWarmup = false;
|
||||
}
|
||||
|
||||
bool RPCIsInWarmup(std::string *outStatus)
|
||||
{
|
||||
LOCK(cs_rpcWarmup);
|
||||
if (outStatus)
|
||||
*outStatus = rpcWarmupStatus;
|
||||
return fRPCInWarmup;
|
||||
}
|
||||
|
||||
void RPCRunHandler(const boost::system::error_code& err, boost::function<void(void)> func)
|
||||
{
|
||||
if (!err)
|
||||
|
@ -947,7 +955,7 @@ void ServiceConnection(AcceptedConnection *conn)
|
|||
break;
|
||||
|
||||
// Process via HTTP REST API
|
||||
} else if (strURI.substr(0, 6) == "/rest/") {
|
||||
} else if (strURI.substr(0, 6) == "/rest/" && GetBoolArg("-rest", false)) {
|
||||
if (!HTTPReq_REST(conn, strURI, mapHeaders, fRun))
|
||||
break;
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@ void SetRPCWarmupStatus(const std::string& newStatus);
|
|||
/* Mark warmup as done. RPC calls will be processed from now on. */
|
||||
void SetRPCWarmupFinished();
|
||||
|
||||
/* returns the current warmup state. */
|
||||
bool RPCIsInWarmup(std::string *statusOut);
|
||||
|
||||
/**
|
||||
* Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
|
||||
* the right number of arguments are passed, just that any passed are the correct type.
|
||||
|
|
Loading…
Reference in a new issue