Skip to content

Commit

Permalink
HTTP/1.1 default keep-alive to avoid TIME_WAIT
Browse files Browse the repository at this point in the history
ithewei committed Dec 7, 2020
1 parent 5f43167 commit 03ce9e8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion http/server/HttpServer.cpp
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ static void on_recv(hio_t* io, void* _buf, int readbytes) {
}
res->headers["Server"] = s_Server;
// Connection:
bool keepalive = false;
bool keepalive = true;
auto iter_keepalive = req->headers.find("connection");
if (iter_keepalive != req->headers.end()) {
if (stricmp(iter_keepalive->second.c_str(), "keep-alive") == 0) {
@@ -144,6 +144,9 @@ static void on_recv(hio_t* io, void* _buf, int readbytes) {
keepalive = false;
}
}
else if (req->http_major == 1 && req->http_minor == 0) {
keepalive = false;
}
if (keepalive) {
res->headers["Connection"] = "keep-alive";
}

0 comments on commit 03ce9e8

Please sign in to comment.