diff --git a/source/common/http/filter_manager.cc b/source/common/http/filter_manager.cc index f514ee075444..ce0fe0cd8576 100644 --- a/source/common/http/filter_manager.cc +++ b/source/common/http/filter_manager.cc @@ -466,29 +466,31 @@ void ActiveStreamDecoderFilter::encode1xxHeaders(ResponseHeaderMapPtr&& headers) } } -void ActiveStreamDecoderFilter::maybeStopDecoderFilterChain(bool end_stream) { - filter_encoded_end_stream_ = end_stream; - if (end_stream && end_stream_ && !parent_.state_.decoder_filter_chain_complete_) { +void ActiveStreamDecoderFilter::maybeMarkDecoderFilterTerminal(bool encoded_end_stream) { + filter_encoded_end_stream_ = encoded_end_stream; + // If this filter encoded end_stream and the decoder filter chain has not yet been finished + // then make this filter terminal. Decoding will not go past this filter. + if (encoded_end_stream && end_stream_ && !parent_.state_.decoder_filter_chain_complete_) { parent_.state_.decoder_filter_chain_aborted_ = true; } } void ActiveStreamDecoderFilter::encodeHeaders(ResponseHeaderMapPtr&& headers, bool end_stream, absl::string_view details) { - maybeStopDecoderFilterChain(end_stream); + maybeMarkDecoderFilterTerminal(end_stream); parent_.streamInfo().setResponseCodeDetails(details); parent_.filter_manager_callbacks_.setResponseHeaders(std::move(headers)); parent_.encodeHeaders(nullptr, *parent_.filter_manager_callbacks_.responseHeaders(), end_stream); } void ActiveStreamDecoderFilter::encodeData(Buffer::Instance& data, bool end_stream) { - maybeStopDecoderFilterChain(end_stream); + maybeMarkDecoderFilterTerminal(end_stream); parent_.encodeData(nullptr, data, end_stream, FilterManager::FilterIterationStartState::CanStartFromCurrent); } void ActiveStreamDecoderFilter::encodeTrailers(ResponseTrailerMapPtr&& trailers) { - maybeStopDecoderFilterChain(true); + maybeMarkDecoderFilterTerminal(true); parent_.filter_manager_callbacks_.setResponseTrailers(std::move(trailers)); parent_.encodeTrailers(nullptr, *parent_.filter_manager_callbacks_.responseTrailers()); } diff --git a/source/common/http/filter_manager.h b/source/common/http/filter_manager.h index f4b5184d9bf1..24070f66956d 100644 --- a/source/common/http/filter_manager.h +++ b/source/common/http/filter_manager.h @@ -286,7 +286,7 @@ struct ActiveStreamDecoderFilter : public ActiveStreamFilterBase, // This allows non-terminal filters (i.e. cache filter) to encode responses when independent // half-close is enabled. Encoding end_stream effectively makes the filter terminal - decoder // filer chain will not go past this filter. - void maybeStopDecoderFilterChain(bool end_stream); + void maybeMarkDecoderFilterTerminal(bool encoded_end_stream); StreamDecoderFilterSharedPtr handle_; bool is_grpc_request_{}; diff --git a/test/common/http/conn_manager_impl_test_2.cc b/test/common/http/conn_manager_impl_test_2.cc index 5fa5fdf2c6a3..af92cc9cac90 100644 --- a/test/common/http/conn_manager_impl_test_2.cc +++ b/test/common/http/conn_manager_impl_test_2.cc @@ -49,7 +49,7 @@ TEST_F(HttpConnectionManagerImplTest, ResponseBeforeRequestCompleteWithUpstreamH TestScopedRuntime scoped_runtime; scoped_runtime.mergeValues( {{"envoy.reloadable_features.allow_multiplexed_upstream_half_close", "true"}}); - setup(false, "envoy-server-test"); + setup(); setupFilterChain(1, 0); EXPECT_CALL(*decoder_filters_[0], decodeHeaders(_, false)) @@ -541,7 +541,7 @@ TEST_F(HttpConnectionManagerImplTest, DrainConnectionUponCompletionVsOnDrainTime Event::MockTimer* connection_duration_timer = setUpTimer(); EXPECT_CALL(*connection_duration_timer, enableTimer(_, _)); // Set up connection. - setup(false, ""); + setup(); // Create a filter so we can encode responses. MockStreamDecoderFilter* filter = new NiceMock(); @@ -1910,7 +1910,7 @@ TEST_F(HttpConnectionManagerImplTest, FilterHeadReply) { TEST_F(HttpConnectionManagerImplTest, LocalReplyStopsDecoding) { InSequence s; - setup(false, ""); + setup(); EXPECT_CALL(*codec_, dispatch(_)).WillOnce(Invoke([&](Buffer::Instance& data) -> Http::Status { decoder_ = &conn_manager_->newStream(response_encoder_); @@ -4449,7 +4449,7 @@ TEST_F(HttpConnectionManagerImplTest, EncodingByNonTerminalFilter) { TestScopedRuntime scoped_runtime; scoped_runtime.mergeValues( {{"envoy.reloadable_features.allow_multiplexed_upstream_half_close", "false"}}); - setup(false, ""); + setup(); constexpr int total_filters = 3; constexpr int ecoder_filter_index = 1; setupFilterChain(total_filters, total_filters); @@ -4501,7 +4501,7 @@ TEST_F(HttpConnectionManagerImplTest, EncodingByNonTerminalFilterWithIndependent TestScopedRuntime scoped_runtime; scoped_runtime.mergeValues( {{"envoy.reloadable_features.allow_multiplexed_upstream_half_close", "true"}}); - setup(false, ""); + setup(); constexpr int total_filters = 3; constexpr int ecoder_filter_index = 1; setupFilterChain(total_filters, total_filters); @@ -4556,7 +4556,7 @@ TEST_F(HttpConnectionManagerImplTest, DecodingByNonTerminalEncoderFilterWithInde TestScopedRuntime scoped_runtime; scoped_runtime.mergeValues( {{"envoy.reloadable_features.allow_multiplexed_upstream_half_close", "true"}}); - setup(false, ""); + setup(); constexpr int total_filters = 3; constexpr int ecoder_filter_index = 1; setupFilterChain(total_filters, total_filters); @@ -4625,7 +4625,7 @@ TEST_F(HttpConnectionManagerImplTest, DecodingWithAddedTrailersByNonTerminalEnco TestScopedRuntime scoped_runtime; scoped_runtime.mergeValues( {{"envoy.reloadable_features.allow_multiplexed_upstream_half_close", "true"}}); - setup(false, ""); + setup(); constexpr int total_filters = 3; constexpr int ecoder_filter_index = 1; setupFilterChain(total_filters, total_filters);