diff --git a/examples/shrpx_downstream.cc b/examples/shrpx_downstream.cc index 486ffe6d..0df0d4be 100644 --- a/examples/shrpx_downstream.cc +++ b/examples/shrpx_downstream.cc @@ -522,7 +522,25 @@ int htp_hdrs_completecb(http_parser *htp) downstream->set_response_connection_close(!http_should_keep_alive(htp)); downstream->set_response_state(Downstream::HEADER_COMPLETE); downstream->get_upstream()->on_downstream_header_complete(downstream); - return 0; + + if(downstream->tunnel_established()) { + downstream->get_downstream_connection()->set_tunneling_timeout(); + // For tunneling, we remove upstream read timeouts. But it seems + // libevent cannot remove timeouts for SSL based bufferevent. Set + // long timeout here as a workaround. + timeval rtv = { 3600*24, 0 }; + timeval wtv = { 30, 0 }; + downstream->get_upstream()->get_client_handler() + ->set_upstream_timeouts(&rtv, &wtv); + } + + if(downstream->get_request_method() == "HEAD") { + // Ignore the response body. HEAD response may contain + // Content-Length or Transfer-Encoding: chunked. + return 1; + } else { + return 0; + } } } // namespace @@ -572,21 +590,10 @@ int htp_msg_completecb(http_parser *htp) Downstream *downstream; downstream = reinterpret_cast(htp->data); - if(downstream->tunnel_established()) { - // For tunneling, we remove timeouts. - downstream->get_downstream_connection()->remove_timeouts(); - } - downstream->set_response_state(Downstream::MSG_COMPLETE); downstream->get_upstream()->on_downstream_body_complete(downstream); - if(downstream->get_request_method() == "HEAD") { - // Ignore the response body. HEAD response may contain - // Content-Length or Transfer-Encoding: chunked. - return 1; - } else { - return 0; - } + return 0; } } // namespace diff --git a/examples/shrpx_downstream_connection.cc b/examples/shrpx_downstream_connection.cc index 7e22e688..bf77ef5c 100644 --- a/examples/shrpx_downstream_connection.cc +++ b/examples/shrpx_downstream_connection.cc @@ -110,10 +110,11 @@ void DownstreamConnection::start_waiting_response() } } -void DownstreamConnection::remove_timeouts() +void DownstreamConnection::set_tunneling_timeout() { if(bev_) { - bufferevent_set_timeouts(bev_, 0, 0); + bufferevent_set_timeouts(bev_, 0, + &get_config()->downstream_write_timeout); } } diff --git a/examples/shrpx_downstream_connection.h b/examples/shrpx_downstream_connection.h index beb4b9d3..edef7714 100644 --- a/examples/shrpx_downstream_connection.h +++ b/examples/shrpx_downstream_connection.h @@ -47,7 +47,7 @@ public: ClientHandler* get_client_handler(); Downstream* get_downstream(); void start_waiting_response(); - void remove_timeouts(); + void set_tunneling_timeout(); private: ClientHandler *client_handler_; bufferevent *bev_;