diff --git a/proxy/http2/Http2CommonSession.cc b/proxy/http2/Http2CommonSession.cc index 80d16a6cfc4..613d6a1de42 100644 --- a/proxy/http2/Http2CommonSession.cc +++ b/proxy/http2/Http2CommonSession.cc @@ -406,10 +406,20 @@ Http2CommonSession::do_process_frame_read(int event, VIO *vio, bool inside_frame bool Http2CommonSession::_should_do_something_else() { + if (this->_interrupt_reading_frames) { + this->_interrupt_reading_frames = false; + return true; + } // Do something else every 128 incoming frames if connection state isn't closed return (this->_n_frame_read & 0x7F) == 0 && !connection_state.is_state_closed(); } +void +Http2CommonSession::interrupt_reading_frames() +{ + this->_interrupt_reading_frames = true; +} + int64_t Http2CommonSession::write_avail() { diff --git a/proxy/http2/Http2CommonSession.h b/proxy/http2/Http2CommonSession.h index 6eb42c3dd02..8209cf00bac 100644 --- a/proxy/http2/Http2CommonSession.h +++ b/proxy/http2/Http2CommonSession.h @@ -114,6 +114,8 @@ class Http2CommonSession virtual void set_no_activity_timeout() = 0; + void interrupt_reading_frames(); + /////////////////// // Variables Http2ConnectionState connection_state; @@ -166,6 +168,9 @@ class Http2CommonSession int64_t read_from_early_data = 0; bool cur_frame_from_early_data = false; + +private: + bool _interrupt_reading_frames = false; }; /////////////////////////////////////////////// diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index f99ef6bbf08..fbc53d9f382 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -487,6 +487,8 @@ Http2ConnectionState::rcv_headers_frame(const Http2Frame &frame) stream->send_request(*this); } } + // Give a chance to send response before reading next frame. + this->session->interrupt_reading_frames(); } else { // NOTE: Expect CONTINUATION Frame. Do NOT change state of stream or decode // Header Blocks. @@ -1047,6 +1049,8 @@ Http2ConnectionState::rcv_continuation_frame(const Http2Frame &frame) stream->new_transaction(frame.is_from_early_data()); // Send request header to SM stream->send_request(*this); + // Give a chance to send response before reading next frame. + this->session->interrupt_reading_frames(); } else { // NOTE: Expect another CONTINUATION Frame. Do nothing. Http2StreamDebug(this->session, stream_id, "No END_HEADERS flag, expecting CONTINUATION frame"); diff --git a/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_data.yaml b/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_data.yaml index d505778f5ea..60bfa6f7ace 100644 --- a/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_data.yaml +++ b/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_data.yaml @@ -9,6 +9,7 @@ sessions: - name: tcp - name: ip version: 4 + keep-connection-open: 2s transactions: - client-request: frames: diff --git a/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_headers.yaml b/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_headers.yaml index 58415705a00..27df8510302 100644 --- a/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_headers.yaml +++ b/tests/gold_tests/h2/replay_rst_stream/http2_rst_stream_client_after_headers.yaml @@ -9,6 +9,7 @@ sessions: - name: tcp - name: ip version: 4 + keep-connection-open: 2s transactions: - client-request: frames: