Skip to content

Commit 1d14b9e

Browse files
authored
http: delaying filter stack creation until full headers have been received (#3574)
This is a precursor to creating a custom filter stack for websocket vs HTTP. Risk Level: High (All of the integration test pass. I am still wary) Testing: existing tests pass Docs Changes: n/a Release Notes: not included Part of #3301 Signed-off-by: Alyssa Wilk <[email protected]>
1 parent 4882bb5 commit 1d14b9e

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

source/common/http/conn_manager_impl.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ StreamDecoder& ConnectionManagerImpl::newStream(StreamEncoder& response_encoder)
189189
new_stream->response_encoder_ = &response_encoder;
190190
new_stream->response_encoder_->getStream().addCallbacks(*new_stream);
191191
new_stream->buffer_limit_ = new_stream->response_encoder_->getStream().bufferLimit();
192-
config_.filterFactory().createFilterChain(*new_stream);
193-
// Make sure new streams are apprised that the underlying connection is blocked.
194-
if (read_callbacks_->connection().aboveHighWatermark()) {
195-
new_stream->callHighWatermarkCallbacks();
196-
}
197192
new_stream->moveIntoList(std::move(new_stream), streams_);
198193
return **streams_.begin();
199194
}
@@ -445,8 +440,10 @@ const Network::Connection* ConnectionManagerImpl::ActiveStream::connection() {
445440
}
446441

447442
void ConnectionManagerImpl::ActiveStream::decodeHeaders(HeaderMapPtr&& headers, bool end_stream) {
448-
maybeEndDecode(end_stream);
449443
request_headers_ = std::move(headers);
444+
createFilterChain();
445+
446+
maybeEndDecode(end_stream);
450447

451448
ENVOY_STREAM_LOG(debug, "request headers complete (end_stream={}):\n{}", *this, end_stream,
452449
*request_headers_);
@@ -1114,6 +1111,14 @@ void ConnectionManagerImpl::ActiveStream::setBufferLimit(uint32_t new_limit) {
11141111
}
11151112
}
11161113

1114+
void ConnectionManagerImpl::ActiveStream::createFilterChain() {
1115+
connection_manager_.config_.filterFactory().createFilterChain(*this);
1116+
// Make sure new streams are apprised that the underlying connection is blocked.
1117+
if (connection_manager_.read_callbacks_->connection().aboveHighWatermark()) {
1118+
callHighWatermarkCallbacks();
1119+
}
1120+
}
1121+
11171122
void ConnectionManagerImpl::ActiveStreamFilterBase::commonContinue() {
11181123
// TODO(mattklein123): Raise an error if this is called during a callback.
11191124
if (!canContinue()) {

source/common/http/conn_manager_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>,
360360

361361
// Possibly increases buffer_limit_ to the value of limit.
362362
void setBufferLimit(uint32_t limit);
363+
// Set up the Encoder/Decoder filter chain.
364+
void createFilterChain();
363365

364366
ConnectionManagerImpl& connection_manager_;
365367
Router::ConfigConstSharedPtr snapped_route_config_;

test/common/http/conn_manager_impl_test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,14 +1712,13 @@ TEST_F(HttpConnectionManagerImplTest, DownstreamDisconnect) {
17121712
data.drain(2);
17131713
}));
17141714

1715-
setupFilterChain(1, 0);
1715+
EXPECT_CALL(filter_factory_, createFilterChain(_)).Times(0);
17161716

17171717
// Kick off the incoming data.
17181718
Buffer::OwnedImpl fake_input("1234");
17191719
conn_manager_->onData(fake_input, false);
17201720

17211721
// Now raise a remote disconnection, we should see the filter get reset called.
1722-
EXPECT_CALL(*decoder_filters_[0], onDestroy());
17231722
conn_manager_->onEvent(Network::ConnectionEvent::RemoteClose);
17241723
}
17251724

@@ -1732,10 +1731,9 @@ TEST_F(HttpConnectionManagerImplTest, DownstreamProtocolError) {
17321731
throw CodecProtocolException("protocol error");
17331732
}));
17341733

1735-
setupFilterChain(1, 0);
1734+
EXPECT_CALL(filter_factory_, createFilterChain(_)).Times(0);
17361735

17371736
// A protocol exception should result in reset of the streams followed by a local close.
1738-
EXPECT_CALL(*decoder_filters_[0], onDestroy());
17391737
EXPECT_CALL(filter_callbacks_.connection_, close(Network::ConnectionCloseType::FlushWrite));
17401738

17411739
// Kick off the incoming data.

0 commit comments

Comments
 (0)