Test that Http2HeaderBlock order is preserved. This is to test that Http2HeaderBlock does not have any magic to reorder headers, for example, to move pseudo-header fields before regular ones for spec compliance. In contrast, note that HpackEncoder moves pseudo-headers to the beginning of the header block when encoding. PiperOrigin-RevId: 474136110
diff --git a/quiche/spdy/core/http2_header_block_test.cc b/quiche/spdy/core/http2_header_block_test.cc index 4624d7b..1ad045f 100644 --- a/quiche/spdy/core/http2_header_block_test.cc +++ b/quiche/spdy/core/http2_header_block_test.cc
@@ -275,5 +275,21 @@ EXPECT_EQ(block_copy.TotalBytesUsed(), Http2HeaderBlockSize(block_copy)); } +// The order of header fields is preserved. Note that all pseudo-header fields +// must appear before regular header fields, both in HTTP/2 and HTTP/3, see +// https://www.rfc-editor.org/rfc/rfc9113.html#name-http-control-data and +// https://www.rfc-editor.org/rfc/rfc9114.html#name-http-control-data. It is +// the responsibility of the higher layer to add header fields in the correct +// order. +TEST(Http2HeaderBlockTest, OrderPreserved) { + Http2HeaderBlock block; + block[":method"] = "GET"; + block["foo"] = "bar"; + block[":path"] = "/"; + + EXPECT_THAT(block, ElementsAre(Pair(":method", "GET"), Pair("foo", "bar"), + Pair(":path", "/"))); +} + } // namespace test } // namespace spdy