From d26ee036134c1286ab990574ab5b7758c674697e Mon Sep 17 00:00:00 2001 From: Maksim Kolinichenko Date: Fri, 27 Jul 2018 17:26:14 +0300 Subject: [PATCH 1/2] Fixed request parsing regex typo --- httplib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index 5fb8308..3fd843d 100644 --- a/httplib.h +++ b/httplib.h @@ -1528,7 +1528,7 @@ inline bool Server::parse_request_line(const char* s, Request& req) std::cmatch m; if (std::regex_match(s, m, re)) { - req.version = std::string(m[4]); + req.version = std::string(m[5]); req.method = std::string(m[1]); req.target = std::string(m[2]); req.path = detail::decode_url(m[3]); From 15ed1b4883c63bce20c62d08ab9b1d3e1e24bc25 Mon Sep 17 00:00:00 2001 From: Maksim Kolinichenko Date: Fri, 27 Jul 2018 17:39:04 +0300 Subject: [PATCH 2/2] Add Keep-Alive header to response --- httplib.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index 3fd843d..2544c88 100644 --- a/httplib.h +++ b/httplib.h @@ -1560,10 +1560,14 @@ inline void Server::write_response(Stream& strm, bool last_connection, const Req // Headers if (last_connection || - req.version == "HTTP/1.0" || req.get_header_value("Connection") == "close") { res.set_header("Connection", "close"); } + + if (!last_connection && + req.get_header_value("Connection") == "Keep-Alive") { + res.set_header("Connection", "Keep-Alive"); + } if (!res.body.empty()) { #ifdef CPPHTTPLIB_ZLIB_SUPPORT