From f776c50d43d6328adaa7c31eb090643b82801f15 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 14 Aug 2014 12:48:30 +0900 Subject: [PATCH] nghttpx: Just record error code when RST_STREAM is received libnghttp2 will call on_stream_close callback when RST_STREAM is received. So we can use on_stream_close callback to handle existing stream, instead of on_frame_recv callback. --- src/shrpx_http2_session.cc | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index ce06ccb2..86a6e3e8 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -767,7 +767,19 @@ int on_stream_close_callback downstream->reset_response_datalen(); - if(error_code == NGHTTP2_NO_ERROR) { + if(downstream->get_upgraded() && + downstream->get_response_state() == Downstream::HEADER_COMPLETE) { + // For tunneled connection, we have to submit RST_STREAM to + // upstream *after* whole response body is sent. We just set + // MSG_COMPLETE here. Upstream will take care of that. + if(LOG_ENABLED(INFO)) { + SSLOG(INFO, http2session) << "RST_STREAM against tunneled stream " + << "stream_id=" + << stream_id; + } + downstream->get_upstream()->on_downstream_body_complete(downstream); + downstream->set_response_state(Downstream::MSG_COMPLETE); + } else if(error_code == NGHTTP2_NO_ERROR) { if(downstream->get_response_state() != Downstream::MSG_COMPLETE) { downstream->set_response_state(Downstream::MSG_RESET); } @@ -1149,23 +1161,7 @@ int on_frame_recv_callback auto downstream = sd->dconn->get_downstream(); if(downstream && downstream->get_downstream_stream_id() == frame->hd.stream_id) { - if(downstream->get_upgraded() && - downstream->get_response_state() == Downstream::HEADER_COMPLETE) { - // For tunneled connection, we have to submit RST_STREAM to - // upstream *after* whole response body is sent. We just set - // MSG_COMPLETE here. Upstream will take care of that. - if(LOG_ENABLED(INFO)) { - SSLOG(INFO, http2session) << "RST_STREAM against tunneled stream " - << "stream_id=" - << frame->hd.stream_id; - } - downstream->get_upstream()->on_downstream_body_complete(downstream); - downstream->set_response_state(Downstream::MSG_COMPLETE); - } else { - // If we got RST_STREAM, just flag MSG_RESET to indicate - // upstream connection must be terminated. - downstream->set_response_state(Downstream::MSG_RESET); - } + downstream->set_response_rst_stream_error_code (frame->rst_stream.error_code); call_downstream_readcb(http2session, downstream);