Skip to content

Commit

Permalink
[http codec] case-insensetive transfer-encoding checks (envoyproxy#10055
Browse files Browse the repository at this point in the history
) (#218)

Signed-off-by: Oleg Guba <oleg@dropbox.com>
Co-authored-by: Yuchen Dai <silentdai@gmail.com>

Co-authored-by: Oleg Guba <oleg@dropbox.com>
  • Loading branch information
lambdai and veshij authored Jun 3, 2020
1 parent 7043f39 commit 2169972
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/common/http/http1/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ int ConnectionImpl::onHeadersCompleteBase() {
absl::string_view encoding = current_header_map_->TransferEncoding()->value().getStringView();
if (Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.reject_unsupported_transfer_encodings") &&
encoding != Headers::get().TransferEncodingValues.Identity &&
encoding != Headers::get().TransferEncodingValues.Chunked) {
!absl::EqualsIgnoreCase(encoding, Headers::get().TransferEncodingValues.Identity) &&
!absl::EqualsIgnoreCase(encoding, Headers::get().TransferEncodingValues.Chunked)) {
error_code_ = Http::Code::NotImplemented;
sendProtocolError();
throw CodecProtocolException("http/1.1 protocol error: unsupported transfer encoding");
Expand Down
24 changes: 24 additions & 0 deletions test/common/http/http1/codec_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,30 @@ TEST_F(Http1ServerConnectionImplTest, ChunkedBody) {
EXPECT_EQ(0U, buffer.length());
}

TEST_F(Http1ServerConnectionImplTest, ChunkedBodyCase) {
initialize();

InSequence sequence;

NiceMock<MockStreamDecoder> decoder;
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

TestHeaderMapImpl expected_headers{
{":path", "/"},
{":method", "POST"},
{"transfer-encoding", "Chunked"},
};
EXPECT_CALL(decoder, decodeHeaders_(HeaderMapEqual(&expected_headers), false)).Times(1);
Buffer::OwnedImpl expected_data("Hello World");
EXPECT_CALL(decoder, decodeData(BufferEqual(&expected_data), false)).Times(1);
EXPECT_CALL(decoder, decodeData(_, true)).Times(1);

Buffer::OwnedImpl buffer(
"POST / HTTP/1.1\r\ntransfer-encoding: Chunked\r\n\r\nb\r\nHello World\r\n0\r\n\r\n");
codec_->dispatch(buffer);
EXPECT_EQ(0U, buffer.length());
}

// Currently http_parser does not support chained transfer encodings.
TEST_F(Http1ServerConnectionImplTest, IdentityAndChunkedBody) {
initialize();
Expand Down

0 comments on commit 2169972

Please sign in to comment.