Skip to content

Commit

Permalink
http: Send "Connection: close" header if shutdown is requested
Browse files Browse the repository at this point in the history
Sending the header "Connection: close" makes libevent close persistent
connections (implicit with HTTP 1.1) which cleans the event base when
shutdown is requested.
  • Loading branch information
promag committed Nov 23, 2018
1 parent 02e1e4e commit 18e9685
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <util/strencodings.h>
#include <netbase.h>
#include <rpc/protocol.h> // For HTTP status codes
#include <shutdown.h>
#include <sync.h>
#include <ui_interface.h>

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

0 comments on commit 18e9685

Please sign in to comment.