From 4b6f124b7e87e80d72712aae6b862cd8437a1b56 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 3 Jul 2014 21:44:29 +0900 Subject: [PATCH] Add API to check half-closed state for both direction of stream --- lib/includes/nghttp2/nghttp2.h | 19 +++++++++++++++++++ lib/nghttp2_session.c | 28 ++++++++++++++++++++++++++++ src/shrpx_downstream.cc | 13 +------------ src/shrpx_downstream.h | 4 ---- src/shrpx_http2_upstream.cc | 6 +----- 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 940980eb..3a2a328c 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -1995,6 +1995,25 @@ int32_t nghttp2_session_get_effective_local_window_size int32_t nghttp2_session_get_stream_remote_window_size(nghttp2_session* session, int32_t stream_id); + +/** + * @function + * + * Returns 1 if local peer half closed the given stream |stream_id|. + * Returns 0 if it did not. Returns -1 if no such stream exists. + */ +int nghttp2_session_get_stream_local_close(nghttp2_session* session, + int32_t stream_id); + +/** + * @function + * + * Returns 1 if remote peer half closed the given stream |stream_id|. + * Returns 0 if it did not. Returns -1 if no such stream exists. + */ +int nghttp2_session_get_stream_remote_close(nghttp2_session* session, + int32_t stream_id); + /** * @function * diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 82d4b2c0..291e4ba5 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -5627,3 +5627,31 @@ int nghttp2_session_upgrade(nghttp2_session *session, } return 0; } + +int nghttp2_session_get_stream_local_close(nghttp2_session* session, + int32_t stream_id) +{ + nghttp2_stream *stream; + + stream = nghttp2_session_get_stream(session, stream_id); + + if(!stream) { + return -1; + } + + return (stream->shut_flags & NGHTTP2_SHUT_WR) != 0; +} + +int nghttp2_session_get_stream_remote_close(nghttp2_session* session, + int32_t stream_id) +{ + nghttp2_stream *stream; + + stream = nghttp2_session_get_stream(session, stream_id); + + if(!stream) { + return -1; + } + + return (stream->shut_flags & NGHTTP2_SHUT_RD) != 0; +} diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index f02a0dc5..41c47134 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -67,8 +67,7 @@ Downstream::Downstream(Upstream *upstream, int stream_id, int priority) request_http2_expect_body_(false), chunked_response_(false), response_connection_close_(false), - response_header_key_prev_(false), - rst_stream_after_end_stream_(false) + response_header_key_prev_(false) {} Downstream::~Downstream() @@ -796,14 +795,4 @@ void Downstream::set_response_rst_stream_error_code response_rst_stream_error_code_ = error_code; } -bool Downstream::get_rst_stream_after_end_stream() const -{ - return rst_stream_after_end_stream_; -} - -void Downstream::set_rst_stream_after_end_stream(bool f) -{ - rst_stream_after_end_stream_ = f; -} - } // namespace shrpx diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index 01e04552..91bfd387 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -282,10 +282,6 @@ private: bool chunked_response_; bool response_connection_close_; bool response_header_key_prev_; - - // If true, RST_STREAM with NGHTTP2_NO_ERROR is issued after - // response is closed with END_STREAM. - bool rst_stream_after_end_stream_; }; } // namespace shrpx diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index cd46c308..399e2037 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1013,9 +1013,7 @@ ssize_t downstream_data_read_callback(nghttp2_session *session, if(!downstream->get_upgraded()) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; - if(downstream->get_rst_stream_after_end_stream() && - downstream->get_request_state() != Downstream::MSG_COMPLETE) { - + if(nghttp2_session_get_stream_remote_close(session, stream_id) == 0) { upstream->rst_stream(downstream, NGHTTP2_NO_ERROR); } } else { @@ -1079,8 +1077,6 @@ int Http2Upstream::error_reply(Downstream *downstream, status_code, downstream); } - downstream->set_rst_stream_after_end_stream(true); - return 0; }