Copilot commented on code in PR #3751:
URL: https://github.com/apache/brpc/pull/3751#discussion_r4588500122
##########
test/brpc_http_rpc_protocol_unittest.cpp:
##########
@@ -2675,6 +2675,82 @@ TEST_F(HttpTest,
h2_oversized_single_headers_block_rejected) {
delete sctx;
}
+void AppendH2Frame(butil::IOBuf* out, brpc::policy::H2FrameType type,
+ uint8_t flags, int stream_id, const butil::IOBuf& payload) {
+ char headbuf[brpc::policy::FRAME_HEAD_SIZE];
+ brpc::policy::SerializeFrameHead(headbuf, payload.size(), type, flags,
+ stream_id);
+ out->append(headbuf, sizeof(headbuf));
+ out->append(payload);
+}
+
+// HEADERS without END_STREAM, then DATA, then the trailer section in a
+// HEADERS frame with END_STREAM.
+void MakeH2RequestWithTrailers(butil::IOBuf* out, int stream_id,
+ const butil::IOBuf& trailers) {
+ const uint8_t END_STREAM = 0x1;
+ const uint8_t END_HEADERS = 0x4;
+ butil::IOBuf headers;
+ AppendLiteralHeader(&headers, ":method", "POST");
+ AppendLiteralHeader(&headers, ":scheme", "http");
+ AppendLiteralHeader(&headers, ":path", "/EchoService/Echo");
+ AppendLiteralHeader(&headers, ":authority", "127.0.0.1");
+ AppendLiteralHeader(&headers, "content-type", "application/json");
+ AppendLiteralHeader(&headers, "x-forwarded-for", "10.0.0.1");
+ AppendH2Frame(out, brpc::policy::H2_FRAME_HEADERS, END_HEADERS,
+ stream_id, headers);
+ butil::IOBuf body;
+ body.append("{\"message\":\"hello\"}");
+ AppendH2Frame(out, brpc::policy::H2_FRAME_DATA, 0, stream_id, body);
+ AppendH2Frame(out, brpc::policy::H2_FRAME_HEADERS,
+ END_HEADERS | END_STREAM, stream_id, trailers);
+}
+
+// RFC 9110 section 6.5.1: a trailer field must not be merged into the header
+// section. A front-end only rewrites the header section of a request, so a
+// field taken from the trailers would be smuggled past it, the same way as
+// HTTP/1 chunked trailers before they were dropped. RFC 9113 section 8.1:
+// trailers must not carry pseudo-header fields.
+TEST_F(HttpTest, h2_request_trailers_not_merged_into_header) {
+ brpc::policy::H2Context* ctx =
+ new brpc::policy::H2Context(_socket.get(), &_server);
+ ASSERT_EQ(0, ctx->Init());
+ _socket->initialize_parsing_context(&ctx);
+ ASSERT_TRUE(ctx->is_server_side());
+ ctx->_conn_state = brpc::policy::H2_CONNECTION_READY;
+
+ butil::IOBuf trailers;
+ AppendLiteralHeader(&trailers, "x-forwarded-for", "6.6.6.6");
+ AppendLiteralHeader(&trailers, "authorization", "Bearer smuggled");
Review Comment:
This regression test uses the default `0x00` representation for every
trailer field, so it never exercises the HPACK dynamic-table update path. The
implementation specifically relies on decoding and retaining indexed trailer
fields in the connection table while dropping them from `HttpHeader`; add an
incremental-indexing trailer followed by a later indexed field (on the same
connection) to verify that synchronization guarantee.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]