aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/init.cpp1
-rw-r--r--src/rest.cpp8
-rw-r--r--src/rpcprotocol.h1
-rw-r--r--src/rpcserver.cpp10
-rw-r--r--src/rpcserver.h3
5 files changed, 20 insertions, 3 deletions
diff --git a/src/init.cpp b/src/init.cpp
index b73c6e8722..63e72c66d2 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -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";
diff --git a/src/rest.cpp b/src/rest.cpp
index 122b361719..4953d7e717 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -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) {
diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h
index a321338176..f7cd50f9f6 100644
--- a/src/rpcprotocol.h
+++ b/src/rpcprotocol.h
@@ -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
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index 7022c50375..b03016a508 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -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;
diff --git a/src/rpcserver.h b/src/rpcserver.h
index 7395fc23c6..b0e437057b 100644
--- a/src/rpcserver.h
+++ b/src/rpcserver.h
@@ -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.