Skip to content

Commit 18e9685

Browse files
committed
http: Send "Connection: close" header if shutdown is requested
Sending the header "Connection: close" makes libevent close persistent connections (implicit with HTTP 1.1) which cleans the event base when shutdown is requested.
1 parent 02e1e4e commit 18e9685

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/httpserver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <util/strencodings.h>
1111
#include <netbase.h>
1212
#include <rpc/protocol.h> // For HTTP status codes
13+
#include <shutdown.h>
1314
#include <sync.h>
1415
#include <ui_interface.h>
1516

@@ -583,6 +584,9 @@ void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value)
583584
void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
584585
{
585586
assert(!replySent && req);
587+
if (ShutdownRequested()) {
588+
WriteHeader("Connection", "close");
589+
}
586590
// Send event to main http thread to send reply message
587591
struct evbuffer* evb = evhttp_request_get_output_buffer(req);
588592
assert(evb);

0 commit comments

Comments
 (0)