From 8dc0ab8f13b30579205796773fe73ff6bb2d94bf Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Fri, 20 Nov 2026 15:15:44 +0100 Subject: [PATCH 1/2] Treat the HTTP/2 Expect field value as case-insensitive RFC 9110, section 10.1.1 defines the Expect field value as case-insensitive. HTTP/1.1 already compares 100-continue ignoring case but HTTP/2 did not, so no 100 (Continue) response was sent for a request with "Expect: 100-Continue". --- java/org/apache/coyote/http2/Stream.java | 2 +- test/org/apache/coyote/http2/Http2TestBase.java | 11 +++++++++-- .../coyote/http2/TestHttp2Section_8_1.java | 16 ++++++++++++++-- webapps/docs/changelog.xml | 7 +++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index 6893955b05bc..2dcf3a86c4d7 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -552,7 +552,7 @@ public final void emitHeader(String name, String value) throws HpackException { break; } default: { - if ("expect".equals(name) && "100-continue".equals(value)) { + if ("expect".equals(name) && "100-continue".equalsIgnoreCase(value)) { coyoteRequest.setExpectation(true); } if (pseudoHeader) { diff --git a/test/org/apache/coyote/http2/Http2TestBase.java b/test/org/apache/coyote/http2/Http2TestBase.java index 42a8d4e18ec3..48d2b596f109 100644 --- a/test/org/apache/coyote/http2/Http2TestBase.java +++ b/test/org/apache/coyote/http2/Http2TestBase.java @@ -383,6 +383,13 @@ protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPay protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPayload, boolean useExpectation, String contentType, long contentLength, String path, byte[] dataFrameHeader, ByteBuffer dataPayload, byte[] padding, boolean withTrailers, int streamId) { + buildPostRequest(headersFrameHeader, headersPayload, useExpectation ? "100-continue" : null, contentType, + contentLength, path, dataFrameHeader, dataPayload, padding, withTrailers, streamId); + } + + protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPayload, String expectation, + String contentType, long contentLength, String path, byte[] dataFrameHeader, ByteBuffer dataPayload, + byte[] padding, boolean withTrailers, int streamId) { MimeHeaders headers = new MimeHeaders(); headers.addValue(":method").setString(Method.POST); @@ -393,8 +400,8 @@ protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPay } headers.addValue(":path").setString(path); headers.addValue(":authority").setString("localhost:" + getPort()); - if (useExpectation) { - headers.addValue("expect").setString("100-continue"); + if (expectation != null) { + headers.addValue("expect").setString(expectation); } if (contentType != null) { headers.addValue("content-type").setString(contentType); diff --git a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java index 55cda91103ef..7835e8fe1dbd 100644 --- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java +++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java @@ -152,6 +152,18 @@ public void setContinueHandlingResponsePolicy(ContinueResponseTiming policy) thr @Test public void testSendAck() throws Exception { + doTestSendAck("100-continue"); + } + + + @Test + public void testSendAckMixedCase() throws Exception { + // RFC 9110, section 10.1.1: the Expect field value is case-insensitive + doTestSendAck("100-Continue"); + } + + + private void doTestSendAck(String expectation) throws Exception { // makes a request that expects a 100 Continue response and verifies // that the 100 Continue response is received. This does not check // that the correct ContinueHandlingResponsePolicy was followed, just @@ -167,8 +179,8 @@ public void testSendAck() throws Exception { byte[] dataFrameHeader = new byte[9]; ByteBuffer dataPayload = ByteBuffer.allocate(256); - buildPostRequest(headersFrameHeader, headersPayload, true, null, -1, "/simple", dataFrameHeader, dataPayload, - null, false, 3); + buildPostRequest(headersFrameHeader, headersPayload, expectation, null, -1, "/simple", dataFrameHeader, + dataPayload, null, false, 3); // Write the headers writeFrame(headersFrameHeader, headersPayload); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 40cee9a06286..fac3d12573bb 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -370,6 +370,13 @@ that is in asynchronous mode are released if the connection thread raises a stream error for that stream. (markt) + + Treat the value of the Expect header as case insensitive + for HTTP/2 requests, as required by RFC 9110, section 10.1.1, so that a + 100 (Continue) response is sent for + Expect: 100-Continue. Pull request 1263 provided + by Arturo Bernal. + From d39d174ed03f560f7eaf041c3f25656e7543f24e Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Fri, 20 Nov 2026 15:36:13 +0100 Subject: [PATCH 2/2] Treat the HTTP/2 Expect field value as a list of expectations RFC 9110, section 10.1.1 defines Expect as a list. A request with "Expect: foo, 100-continue" over HTTP/2 got neither a 100 (Continue) response nor an immediate final response, so the server waited for the request content. --- java/org/apache/coyote/http2/Stream.java | 18 ++++++++- .../coyote/http2/TestHttp2Section_8_1.java | 40 ++++++++++++++++--- webapps/docs/changelog.xml | 7 ++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index 2dcf3a86c4d7..26c7d8ea3f4b 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -52,6 +52,7 @@ import org.apache.tomcat.util.http.parser.Host; import org.apache.tomcat.util.http.parser.HttpParser; import org.apache.tomcat.util.http.parser.Priority; +import org.apache.tomcat.util.http.parser.TokenList; import org.apache.tomcat.util.net.ApplicationBufferHandler; import org.apache.tomcat.util.net.SocketEvent; import org.apache.tomcat.util.net.WriteBuffer; @@ -552,8 +553,21 @@ public final void emitHeader(String name, String value) throws HpackException { break; } default: { - if ("expect".equals(name) && "100-continue".equalsIgnoreCase(value)) { - coyoteRequest.setExpectation(true); + if ("expect".equals(name)) { + // RFC 9110, section 10.1.1: the field value is a case-insensitive list of expectations + if ("100-continue".equalsIgnoreCase(value)) { + coyoteRequest.setExpectation(true); + } else { + Set expectations = new HashSet<>(); + try { + TokenList.parseTokenList(new StringReader(value), expectations); + } catch (IOException ioe) { + // Not possible with StringReader + } + if (expectations.contains("100-continue")) { + coyoteRequest.setExpectation(true); + } + } } if (pseudoHeader) { headerException = new StreamException( diff --git a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java index 7835e8fe1dbd..d3e2de61cfae 100644 --- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java +++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java @@ -152,18 +152,43 @@ public void setContinueHandlingResponsePolicy(ContinueResponseTiming policy) thr @Test public void testSendAck() throws Exception { - doTestSendAck("100-continue"); + doTestSendAck("100-continue", true); } @Test public void testSendAckMixedCase() throws Exception { // RFC 9110, section 10.1.1: the Expect field value is case-insensitive - doTestSendAck("100-Continue"); + doTestSendAck("100-Continue", true); } - private void doTestSendAck(String expectation) throws Exception { + @Test + public void testSendAckList() throws Exception { + // RFC 9110, section 10.1.1: the Expect field value is a list of expectations + doTestSendAck("foo, 100-continue", true); + } + + + @Test + public void testSendAckListWithEmptyElements() throws Exception { + doTestSendAck(",100-continue, ,foo", true); + } + + + @Test + public void testNoAckForOtherExpectation() throws Exception { + doTestSendAck("foo", false); + } + + + @Test + public void testNoAckForContinueWithParameter() throws Exception { + doTestSendAck("100-continue=1", false); + } + + + private void doTestSendAck(String expectation, boolean ack) throws Exception { // makes a request that expects a 100 Continue response and verifies // that the 100 Continue response is received. This does not check // that the correct ContinueHandlingResponsePolicy was followed, just @@ -185,10 +210,13 @@ private void doTestSendAck(String expectation) throws Exception { // Write the headers writeFrame(headersFrameHeader, headersPayload); - parser.readFrame(); + if (ack) { + parser.readFrame(); - Assert.assertEquals("3-HeadersStart\n" + "3-Header-[:status]-[100]\n" + "3-HeadersEnd\n", output.getTrace()); - output.clearTrace(); + Assert.assertEquals("3-HeadersStart\n" + "3-Header-[:status]-[100]\n" + "3-HeadersEnd\n", + output.getTrace()); + output.clearTrace(); + } // Write the body writeFrame(dataFrameHeader, dataPayload); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index fac3d12573bb..6911897a91df 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -377,6 +377,13 @@ Expect: 100-Continue. Pull request 1263 provided by Arturo Bernal. + + Treat the value of the Expect header as a list of + expectations for HTTP/2 requests, as required by RFC 9110, section + 10.1.1, so that a 100 (Continue) response is sent when the + list contains 100-continue. Pull request 1265 + provided by Arturo Bernal. +