From 9303cca4302d354132f1ec514bfdacaad5647267 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 7 Jun 2012 22:40:42 +0900 Subject: [PATCH] Send back Connection: keep-alive for the request with http/1.0 keep-alive --- examples/shrpx_downstream.cc | 12 ++++++++++++ examples/shrpx_downstream.h | 2 ++ examples/shrpx_https_upstream.cc | 3 +++ 3 files changed, 17 insertions(+) diff --git a/examples/shrpx_downstream.cc b/examples/shrpx_downstream.cc index b7a8d74..6103afb 100644 --- a/examples/shrpx_downstream.cc +++ b/examples/shrpx_downstream.cc @@ -116,6 +116,8 @@ void check_request_connection(bool *connection_close, if(util::strieq(item.first.c_str(), "connection")) { if(util::strifind(item.second.c_str(), "close")) { *connection_close = true; + } else if(util::strifind(item.second.c_str(), "keep-alive")) { + *connection_close = false; } } } @@ -155,6 +157,16 @@ void Downstream::set_request_minor(int minor) request_minor_ = minor; } +int Downstream::get_request_major() const +{ + return request_major_; +} + +int Downstream::get_request_minor() const +{ + return request_minor_; +} + Upstream* Downstream::get_upstream() const { return upstream_; diff --git a/examples/shrpx_downstream.h b/examples/shrpx_downstream.h index dfafa5d..7edfcc7 100644 --- a/examples/shrpx_downstream.h +++ b/examples/shrpx_downstream.h @@ -65,6 +65,8 @@ public: void set_request_path(const std::string& path); void set_request_major(int major); void set_request_minor(int minor); + int get_request_major() const; + int get_request_minor() const; int push_request_headers(); bool get_chunked_request() const; bool get_request_connection_close() const; diff --git a/examples/shrpx_https_upstream.cc b/examples/shrpx_https_upstream.cc index 779de53..a2ca1aa 100644 --- a/examples/shrpx_https_upstream.cc +++ b/examples/shrpx_https_upstream.cc @@ -476,6 +476,9 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) } if(get_client_handler()->get_should_close_after_write()) { hdrs += "Connection: close\r\n"; + } else if(downstream->get_request_major() == 1 && + downstream->get_request_minor() == 0) { + hdrs += "Connection: Keep-Alive\r\n"; } hdrs += "Via: "; hdrs += via_value;