diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index 6893955b05bc..d76bf2623378 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -400,7 +400,8 @@ public final void emitHeader(String name, String value) throws HpackException { } if ("te".equals(name)) { - if (!"trailers".equals(value)) { + // "trailers" is an ABNF literal so it is case-insensitive (RFC 9110, section 10.1.4 and RFC 5234) + if (!"trailers".equalsIgnoreCase(value)) { headerException = new StreamException(sm.getString("stream.header.te", getConnectionId(), getIdAsString(), value), Http2Error.PROTOCOL_ERROR, getIdAsInt()); diff --git a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java index 55cda91103ef..dcd26c9c44b4 100644 --- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java +++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java @@ -257,6 +257,58 @@ public void testPseudoHeaderOrder() throws Exception { } + @Test + public void testTeTrailers() throws Exception { + doTestTe("trailers", true); + } + + + @Test + public void testTeTrailersMixedCase() throws Exception { + doTestTe("Trailers", true); + } + + + @Test + public void testTeTrailersUpperCase() throws Exception { + doTestTe("TRAILERS", true); + } + + + @Test + public void testTeInvalid() throws Exception { + doTestTe("gzip", false); + } + + + private void doTestTe(String value, boolean valid) throws Exception { + http2Connect(); + + List
headers = new ArrayList<>(5); + headers.add(new Header(":method", Method.GET)); + headers.add(new Header(":scheme", "http")); + headers.add(new Header(":path", "/simple")); + headers.add(new Header(":authority", "localhost:" + getPort())); + headers.add(new Header("te", value)); + + byte[] headersFrameHeader = new byte[9]; + ByteBuffer headersPayload = ByteBuffer.allocate(128); + + buildGetRequest(headersFrameHeader, headersPayload, null, headers, 3); + + writeFrame(headersFrameHeader, headersPayload); + + parser.readFrame(); + + String trace = output.getTrace(); + if (valid) { + Assert.assertTrue(trace, trace.contains("3-Header-[:status]-[200]")); + } else { + Assert.assertEquals("3-RST-[1]\n", trace); + } + } + + @Test public void testHostHeaderValid() throws Exception { http2Connect(); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 81514f66d0fc..7d337e239714 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -461,6 +461,12 @@ destroy() is only called if init() was called for the handler. (markt) + + Compare the value of the HTTP/2 te request header to + trailers case-insensitively, rather than resetting the + stream when the value is not in lower case. Pull request 1273 + provided by Arturo Bernal. +