From 076788d417390d07bc78dafdb8963df0bb856ec9 Mon Sep 17 00:00:00 2001 From: waga-git Date: Sat, 20 Feb 2016 11:50:17 +0900 Subject: [PATCH 1/2] Support Connection: close header --- server_http.hpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/server_http.hpp b/server_http.hpp index 47e1963..fc96b9b 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -59,7 +59,8 @@ namespace SimpleWeb { class Request { friend class ServerBase; public: - std::string method, path, http_version; + std::string method, path, protocol, http_version; + bool con_close; Content content; @@ -282,10 +283,19 @@ namespace SimpleWeb { if((path_end=line.find(' ', method_end+1))!=std::string::npos) { request->method=line.substr(0, method_end); request->path=line.substr(method_end+1, path_end-method_end-1); - if((path_end+6)http_version=line.substr(path_end+6, line.size()-(path_end+6)-1); + + request->con_close = false; + request->protocol.clear(); + request->http_version.clear(); + + size_t proto_end; + if((proto_end=line.find('/', path_end+1))!=std::string::npos) { + request->protocol=line.substr(path_end+1, proto_end-path_end-1); + request->http_version=line.substr(proto_end+1, line.size()-(proto_end)-1); + } else - request->http_version="1.0"; + request->http_version="1.0"; + getline(stream, line); size_t param_end; @@ -294,8 +304,15 @@ namespace SimpleWeb { if((value_start)header.insert(std::make_pair(line.substr(0, param_end), line.substr(value_start, line.size()-value_start-1))); + if(value_startheader.insert(std::make_pair(key, value)); + + if(boost::iequals(key, "Connection") && boost::iequals(value, "close")) + request->con_close = true; + } } getline(stream, line); @@ -358,7 +375,7 @@ namespace SimpleWeb { catch(const std::exception &e) { return; } - if(http_version>1.05) + if(http_version>1.05 && !request->con_close) read_request_and_content(socket); }); } From c558a0314894f3d34cc4bf28aad2e94eae0e4950 Mon Sep 17 00:00:00 2001 From: waga-git Date: Sat, 20 Feb 2016 12:01:26 +0900 Subject: [PATCH 2/2] Support Connection: close header --- server_http.hpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/server_http.hpp b/server_http.hpp index fc96b9b..1364bad 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -59,8 +59,8 @@ namespace SimpleWeb { class Request { friend class ServerBase; public: - std::string method, path, protocol, http_version; - bool con_close; + std::string method, path, protocol, http_version; + bool con_close; Content content; @@ -284,17 +284,17 @@ namespace SimpleWeb { request->method=line.substr(0, method_end); request->path=line.substr(method_end+1, path_end-method_end-1); - request->con_close = false; - request->protocol.clear(); - request->http_version.clear(); + request->con_close = false; + request->protocol.clear(); + request->http_version.clear(); - size_t proto_end; - if((proto_end=line.find('/', path_end+1))!=std::string::npos) { - request->protocol=line.substr(path_end+1, proto_end-path_end-1); - request->http_version=line.substr(proto_end+1, line.size()-(proto_end)-1); - } + size_t proto_end; + if((proto_end=line.find('/', path_end+1))!=std::string::npos) { + request->protocol=line.substr(path_end+1, proto_end-path_end-1); + request->http_version=line.substr(proto_end+1, line.size()-(proto_end)-1); + } else - request->http_version="1.0"; + request->http_version="1.0"; getline(stream, line); @@ -305,13 +305,13 @@ namespace SimpleWeb { if(line[value_start]==' ') value_start++; if(value_startheader.insert(std::make_pair(key, value)); + request->header.insert(std::make_pair(key, value)); - if(boost::iequals(key, "Connection") && boost::iequals(value, "close")) - request->con_close = true; + if(boost::iequals(key, "Connection") && boost::iequals(value, "close")) + request->con_close = true; } }