Skip to content

Commit

Permalink
Add HttpEncoder::SerializeMetadataFrameHeader().
Browse files Browse the repository at this point in the history
Add HTTP/3 SETTING_ENABLE_METADATA.
Add HTTP/3 METADATA frame type.
Add HttpEncoder::SerializeMetadataFrameHeader() method to serialize METADATA frame header.

Setting identifier and frame type match HTTP/2 ones, see
quiche/spdy/core/metadata_extension.cc.

See envoyproxy/envoy#2394 and design document linked
therein for HTTP/2 METADATA.  HTTP/3 implementation will be very similar.

PiperOrigin-RevId: 457048873
  • Loading branch information
bnc-google authored and copybara-github committed Jun 24, 2022
1 parent c06ea15 commit cb3863a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions quiche/quic/core/http/http_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ std::string H3SettingsToString(Http3AndQpackSettingsIdentifiers identifier) {
RETURN_STRING_LITERAL(SETTINGS_H3_DATAGRAM_DRAFT09);
RETURN_STRING_LITERAL(SETTINGS_WEBTRANS_DRAFT00);
RETURN_STRING_LITERAL(SETTINGS_ENABLE_CONNECT_PROTOCOL);
RETURN_STRING_LITERAL(SETTINGS_ENABLE_METADATA);
}
return absl::StrCat("UNSUPPORTED_SETTINGS_TYPE(", identifier, ")");
}
Expand Down
1 change: 1 addition & 0 deletions quiche/quic/core/http/http_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum Http3AndQpackSettingsIdentifiers : uint64_t {
SETTINGS_WEBTRANS_DRAFT00 = 0x2b603742,
// draft-ietf-httpbis-h3-websockets
SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08,
SETTINGS_ENABLE_METADATA = 0x4d44,
};

// Returns HTTP/3 SETTINGS identifier as a string.
Expand Down
20 changes: 20 additions & 0 deletions quiche/quic/core/http/http_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,24 @@ QuicByteCount HttpEncoder::SerializeWebTransportStreamFrameHeader(
return 0;
}

QuicByteCount HttpEncoder::SerializeMetadataFrameHeader(
QuicByteCount payload_length, std::unique_ptr<char[]>* output) {
QUICHE_DCHECK_NE(0u, payload_length);
QuicByteCount header_length =
QuicDataWriter::GetVarInt62Len(payload_length) +
QuicDataWriter::GetVarInt62Len(
static_cast<uint64_t>(HttpFrameType::METADATA));

*output = std::make_unique<char[]>(header_length);
QuicDataWriter writer(header_length, output->get());

if (WriteFrameHeader(payload_length, HttpFrameType::METADATA, &writer)) {
return header_length;
}
QUIC_DLOG(ERROR)
<< "Http encoder failed when attempting to serialize METADATA "
"frame header.";
return 0;
}

} // namespace quic
5 changes: 5 additions & 0 deletions quiche/quic/core/http/http_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class QUIC_EXPORT_PRIVATE HttpEncoder {
// https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-00.html#name-client-initiated-bidirectio
static QuicByteCount SerializeWebTransportStreamFrameHeader(
WebTransportSessionId session_id, std::unique_ptr<char[]>* output);

// Serializes a METADATA frame header into a new buffer stored in |output|.
// Returns the length of the buffer on success, or 0 otherwise.
static QuicByteCount SerializeMetadataFrameHeader(
QuicByteCount payload_length, std::unique_ptr<char[]>* output);
};

} // namespace quic
Expand Down
11 changes: 11 additions & 0 deletions quiche/quic/core/http/http_encoder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,16 @@ TEST(HttpEncoderTest, SerializeWebTransportStreamFrameHeader) {
"WEBTRANSPORT_STREAM", buffer.get(), length, output, sizeof(output));
}

TEST(HttpEncoderTest, SerializeMetadataFrameHeader) {
std::unique_ptr<char[]> buffer;
uint64_t length = HttpEncoder::SerializeMetadataFrameHeader(
/* payload_length = */ 7, &buffer);
char output[] = {0x40, 0x4d, // type (METADATA, 0x4d, varint encoded)
0x07}; // length
EXPECT_EQ(ABSL_ARRAYSIZE(output), length);
quiche::test::CompareCharArraysWithHexError("METADATA", buffer.get(), length,
output, ABSL_ARRAYSIZE(output));
}

} // namespace test
} // namespace quic
1 change: 1 addition & 0 deletions quiche/quic/core/http/http_frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum class HttpFrameType {
PRIORITY_UPDATE_REQUEST_STREAM = 0xF0700,
// https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-00.html
WEBTRANSPORT_STREAM = 0x41,
METADATA = 0x4d,
};

// 7.2.1. DATA
Expand Down

0 comments on commit cb3863a

Please sign in to comment.