Skip to content

Commit 35bf84c

Browse files
Re-sync with internal repository (#494)
The internal and external repositories are out of sync. This Pull Request attempts to brings them back in sync by patching the GitHub repository. Please carefully review this patch. You must disable ShipIt for your project in order to merge this pull request. DO NOT IMPORT this pull request. Instead, merge it directly on GitHub using the MERGE BUTTON. Re-enable ShipIt after merging.
1 parent 94134b3 commit 35bf84c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

proxygen/lib/http/codec/HTTP2Codec.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,18 @@ ErrorCode HTTP2Codec::parseHeadersImpl(
433433
const folly::Optional<http2::PriorityUpdate>& priority,
434434
const folly::Optional<uint32_t>& promisedStream,
435435
const folly::Optional<ExAttributes>& exAttributes) {
436-
curHeaderBlock_.append(std::move(headerBuf));
436+
if (curHeader_.type == http2::FrameType::CONTINUATION && headerBuf) {
437+
constexpr size_t kMinTailroomForUnshare = 1024;
438+
if (!curHeaderBlock_.empty() &&
439+
curHeaderBlock_.front()->prev()->isSharedOne() &&
440+
headerBuf->prev()->tailroom() > kMinTailroomForUnshare) {
441+
// tail of the current block is shared, but tail of new block has ample
442+
// space. Unshare tail of the new buf to allow future packing
443+
headerBuf->prev()->unshareOne();
444+
}
445+
}
446+
curHeaderBlock_.append(
447+
std::move(headerBuf), /*pack=*/true, /*reuseTail=*/false);
437448
std::unique_ptr<HTTPMessage> msg;
438449
uint32_t headersCompleteStream = curHeader_.stream;
439450

proxygen/lib/http/codec/test/HTTP2CodecTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,28 @@ TEST_F(HTTP2CodecTest, BasicContinuation) {
10061006
EXPECT_EQ(callbacks_.sessionErrors, 0);
10071007
}
10081008

1009+
TEST_F(HTTP2CodecTest, ContinuationChain) {
1010+
auto settings = (HTTPSettings*)upstreamCodec_.getIngressSettings();
1011+
settings->setSetting(SettingsId::MAX_FRAME_SIZE, 3);
1012+
1013+
HTTPMessage req = getBigGetRequest();
1014+
auto id = upstreamCodec_.createStream();
1015+
upstreamCodec_.generateHeader(output_, id, req);
1016+
1017+
parse();
1018+
callbacks_.expectMessage(false, -1, "/");
1019+
#ifndef NDEBUG
1020+
EXPECT_GT(downstreamCodec_.getReceivedFrameCount(), 1);
1021+
#endif
1022+
const auto& headers = callbacks_.msg->getHeaders();
1023+
EXPECT_EQ("coolio", headers.getSingleOrEmpty(HTTP_HEADER_USER_AGENT));
1024+
EXPECT_EQ(callbacks_.messageBegin, 1);
1025+
EXPECT_EQ(callbacks_.headersComplete, 1);
1026+
EXPECT_EQ(callbacks_.messageComplete, 0);
1027+
EXPECT_EQ(callbacks_.streamErrors, 0);
1028+
EXPECT_EQ(callbacks_.sessionErrors, 0);
1029+
}
1030+
10091031
TEST_F(HTTP2CodecTest, BasicContinuationEndStream) {
10101032
// CONTINUATION with END_STREAM flag set on the preceding HEADERS frame
10111033
HTTPMessage req = getBigGetRequest();

0 commit comments

Comments
 (0)