Commit 4b6f124b authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Add API to check half-closed state for both direction of stream

parent 119fb05c
......@@ -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
*
......
......@@ -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;
}
......@@ -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
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment