Browse Source

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)
0.10
Wladimir J. van der Laan 10 years ago
parent
commit
108b19f7ef
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 1
      src/init.cpp
  2. 8
      src/rest.cpp
  3. 1
      src/rpcprotocol.h
  4. 10
      src/rpcserver.cpp
  5. 3
      src/rpcserver.h

1
src/init.cpp

@ -352,6 +352,7 @@ std::string HelpMessage(HelpMessageMode mode) @@ -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";

8
src/rest.cpp

@ -100,7 +100,7 @@ static bool rest_block(AcceptedConnection *conn, @@ -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, @@ -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, @@ -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) {

1
src/rpcprotocol.h

@ -28,6 +28,7 @@ enum HTTPStatusCode @@ -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

10
src/rpcserver.cpp

@ -756,6 +756,14 @@ void SetRPCWarmupFinished() @@ -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) @@ -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;

3
src/rpcserver.h

@ -53,6 +53,9 @@ void SetRPCWarmupStatus(const std::string& newStatus); @@ -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…
Cancel
Save