Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
08ae97c
http1 encode trailers in chunk encoding
Chuongv Oct 18, 2019
5de8533
Add integration test for trailers http1<--->Envoy<--->http2
Chuongv Oct 24, 2019
9c550cb
Use tcp client for integration test for trailers
Chuongv Oct 24, 2019
f0d53cd
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Oct 25, 2019
f9c9f48
Update tests for trailers http1
Chuongv Oct 25, 2019
e002b4b
Undo changes in codec_impl
Chuongv Oct 25, 2019
10a9089
Implementation of trailers support for http1
Chuongv Oct 28, 2019
de29acb
Trailer code clean up
Chuongv Oct 28, 2019
96913f9
Remove unnecessary check for trailers
Chuongv Oct 28, 2019
77ec2ac
Keep the trailer processing on MessageComplete
Chuongv Oct 28, 2019
8b03163
Remove trailer logic in onHeaderComplete
Chuongv Oct 28, 2019
6955a1a
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Oct 28, 2019
92421a8
Accomodate trailers in grpc reverse bridge filter
Chuongv Oct 31, 2019
e7cb695
Reuse encodeFormattedHeaders in encodeTrailers
Chuongv Oct 31, 2019
592e315
Fix the formatting
Chuongv Oct 31, 2019
9e2a48a
Refactor and clean up redundant parser fields
Chuongv Oct 31, 2019
cd56fd8
Add empty space to match the creation of trailers
Chuongv Oct 31, 2019
e9c27e4
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Oct 31, 2019
c70e7b0
Update tests to account for trailers in H1
Chuongv Oct 31, 2019
557e027
Fix formatting
Chuongv Oct 31, 2019
614ff9b
Refactor trailers based on feedback
Chuongv Nov 1, 2019
4205198
Move trailer tests to appropriate test file
Chuongv Nov 1, 2019
b63375d
Fix typo
Chuongv Nov 3, 2019
92d4efc
Add flag to disable support of trailers
Chuongv Nov 8, 2019
dae9233
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Nov 8, 2019
07a0e79
Update docs to include information about encoding h1 trailers
Chuongv Nov 8, 2019
e124271
Update encode trailer docs to include ref link
Chuongv Nov 8, 2019
962afd2
Add next free field to pass formatter
Chuongv Nov 8, 2019
fce0ddb
Correct the label in the version history docs
Chuongv Nov 8, 2019
9f990a5
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Nov 8, 2019
de672b8
Correct the label in the version history docs
Chuongv Nov 11, 2019
b41c492
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Nov 11, 2019
ee426ea
Set the enable_trailers so it defaults to false
Chuongv Nov 13, 2019
1296eff
Switch flag to enable_trailers_ for unit test
Chuongv Nov 13, 2019
ce552b8
Fix spelling
Chuongv Nov 13, 2019
1b87726
Refactor and clean up integration tests
Chuongv Nov 13, 2019
fd5c7de
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Nov 13, 2019
4ed8b97
Move decoding trailers to be guarded by configuration flag
Chuongv Nov 16, 2019
2f18c1c
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Nov 16, 2019
dfbd03e
Don't check for trailers in H2/H1 tests
Chuongv Nov 16, 2019
76a0a6d
Clear out trailers in grpc-web
Chuongv Nov 21, 2019
3041acb
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Nov 21, 2019
e59101d
Address comments and move tests
Chuongv Nov 24, 2019
c784ce4
Use bitfield for enable_trailers
Chuongv Nov 25, 2019
f28af8f
Add more unit and integration tests and address PR feedback
Chuongv Nov 26, 2019
86fed8a
Allow configuration of incomplete streams for Autonomous Upstream
Chuongv Nov 26, 2019
cee19aa
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Nov 26, 2019
32e0c7a
Use bitfields for processing_trailers
Chuongv Nov 26, 2019
4388cf4
Update todo for clearing trailers
Chuongv Nov 26, 2019
8b13bdf
Add some helpful comments on codec_impl.h
Chuongv Nov 27, 2019
4aadf64
Merge branch 'AutonomousStreamIncompleteStream' into http1-trailers-c…
Chuongv Nov 27, 2019
14ac61b
Allow incomplete streams in PipelineTrailers test
Chuongv Nov 27, 2019
41135aa
Move enable_trailers_ for optimal packing
Chuongv Dec 4, 2019
678222d
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Dec 4, 2019
dd6844a
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Dec 4, 2019
b90f535
Address PR comments
Chuongv Dec 6, 2019
fbdf83d
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Dec 6, 2019
9e8be74
Docs not liking the identations
Chuongv Dec 6, 2019
c179840
Fix the identation in the api docs for v3alpha
Chuongv Dec 6, 2019
915fb06
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Dec 9, 2019
ce5cb82
Use set trailers
Chuongv Dec 10, 2019
b406f71
Update docs with attention for enable_trailers
Chuongv Dec 10, 2019
5447d69
Use the new trailers.clear() method
Chuongv Dec 10, 2019
be14d7e
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Dec 10, 2019
0c717f8
Address PR comments
Chuongv Dec 12, 2019
a347b6f
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Dec 13, 2019
fb321d8
Add tests for reverse bridge filter with trailers
Chuongv Dec 13, 2019
d1c66e8
Move trailers/headers to constant strings. Use Consistent Http1 naming
Chuongv Dec 16, 2019
15b6715
Merge remote-tracking branch 'envoy/master' into http1-trailers-chunk…
Chuongv Dec 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions source/common/http/http1/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const StringUtil::CaseUnorderedSet& caseUnorderdSetContainingUpgradeAndHttp2Sett
} // namespace

const std::string StreamEncoderImpl::CRLF = "\r\n";
const std::string StreamEncoderImpl::LAST_CHUNK = "0\r\n\r\n";
// Last chunk as defined here https://tools.ietf.org/html/rfc7230#section-4.1
const std::string StreamEncoderImpl::LAST_CHUNK = "0\r\n";

StreamEncoderImpl::StreamEncoderImpl(ConnectionImpl& connection) : connection_(connection) {
if (connection_.connection().aboveHighWatermark()) {
Expand Down Expand Up @@ -171,7 +172,30 @@ void StreamEncoderImpl::encodeData(Buffer::Instance& data, bool end_stream) {
}
}

void StreamEncoderImpl::encodeTrailers(const HeaderMap&) { endEncode(); }
void StreamEncoderImpl::encodeTrailers(const HeaderMap& trailers) {
if (chunk_encoding_) {
Comment thread
mattklein123 marked this conversation as resolved.
Comment thread
mattklein123 marked this conversation as resolved.
// Finalize the body
connection_.buffer().add(LAST_CHUNK);

// Trailers only matter if it is a chunk transfer encoding
// https://tools.ietf.org/html/rfc7230#section-4.4
trailers.iterate(
Comment thread
mattklein123 marked this conversation as resolved.
[](const HeaderEntry& header, void* context) -> HeaderMap::Iterate {
Buffer::WatermarkBuffer* buffer = static_cast<Buffer::WatermarkBuffer*>(context);
buffer->add(header.key().getStringView());
buffer->add(":");
buffer->add(header.value().getStringView());
buffer->add(CRLF);
return HeaderMap::Iterate::Continue;
},
&connection_.buffer());

connection_.buffer().add(CRLF);
}

connection_.flushOutput();
connection_.onEncodeComplete();
}

void StreamEncoderImpl::encodeMetadata(const MetadataMapVector&) {
connection_.stats().metadata_not_supported_error_.inc();
Expand All @@ -180,6 +204,7 @@ void StreamEncoderImpl::encodeMetadata(const MetadataMapVector&) {
void StreamEncoderImpl::endEncode() {
if (chunk_encoding_) {
connection_.buffer().add(LAST_CHUNK);
connection_.buffer().add(CRLF);
Comment thread
mattklein123 marked this conversation as resolved.
}

connection_.flushOutput();
Expand Down
9 changes: 7 additions & 2 deletions test/common/http/http1/codec_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,13 @@ TEST_F(Http1ServerConnectionImplTest, ChunkedResponse) {
response_encoder->encodeHeaders(headers, false);

Buffer::OwnedImpl data("Hello World");
response_encoder->encodeData(data, true);
EXPECT_EQ("HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\n\r\nb\r\nHello World\r\n0\r\n\r\n",
response_encoder->encodeData(data, false);
Comment thread
Chuongv marked this conversation as resolved.

TestHeaderMapImpl trailers{{"foo", "bar"}, {"foo", "baz"}};
response_encoder->encodeTrailers(trailers);

EXPECT_EQ("HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\n\r\nb\r\nHello "
"World\r\n0\r\nfoo:bar\r\nfoo:baz\r\n\r\n",
output);
}

Expand Down
33 changes: 33 additions & 0 deletions test/integration/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,39 @@ TEST_P(IntegrationTest, HittingGrpcFilterLimitBufferingHeaders) {
HeaderValueOf(Headers::get().GrpcStatus, "2")); // Unknown gRPC error
}

TEST_P(IntegrationTest, TrailersWithHttp1AndHttp2) {
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
Http::TestHeaderMapImpl response_trailers{{"response1", "trailer1"}, {"response2", "trailer2"}};

initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder =
codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"},
{"TE", "trailers"},
{"Accept", "*/*"}});
request_encoder_ = &encoder_decoder.first;
codec_client_->sendData(*request_encoder_, 0, true);

auto response = std::move(encoder_decoder.second);
Comment thread
Chuongv marked this conversation as resolved.
Outdated

waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(default_response_headers_, false);
upstream_request_->encodeData(5, false);
upstream_request_->encodeTrailers(response_trailers);
response->waitForEndStream();

ASSERT_TRUE(upstream_request_->complete());
ASSERT_TRUE(response->complete());

EXPECT_EQ(5, response->body().size());
EXPECT_EQ("aaaaa", response->body());
EXPECT_EQ("200", response->headers().Status()->value().getStringView());
EXPECT_THAT(*response->trailers(), HeaderMapEqualRef(&response_trailers));
Comment thread
Chuongv marked this conversation as resolved.
Outdated
}

TEST_P(IntegrationTest, BadFirstline) {
initialize();
std::string response;
Expand Down