Skip to content

Commit 8dc0ab8

Browse files
committed
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".
1 parent f442523 commit 8dc0ab8

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎java/org/apache/coyote/http2/Stream.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public final void emitHeader(String name, String value) throws HpackException {
552552
break;
553553
}
554554
default: {
555-
if ("expect".equals(name) && "100-continue".equals(value)) {
555+
if ("expect".equals(name) && "100-continue".equalsIgnoreCase(value)) {
556556
coyoteRequest.setExpectation(true);
557557
}
558558
if (pseudoHeader) {

‎test/org/apache/coyote/http2/Http2TestBase.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPay
383383
protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPayload, boolean useExpectation,
384384
String contentType, long contentLength, String path, byte[] dataFrameHeader, ByteBuffer dataPayload,
385385
byte[] padding, boolean withTrailers, int streamId) {
386+
buildPostRequest(headersFrameHeader, headersPayload, useExpectation ? "100-continue" : null, contentType,
387+
contentLength, path, dataFrameHeader, dataPayload, padding, withTrailers, streamId);
388+
}
389+
390+
protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPayload, String expectation,
391+
String contentType, long contentLength, String path, byte[] dataFrameHeader, ByteBuffer dataPayload,
392+
byte[] padding, boolean withTrailers, int streamId) {
386393

387394
MimeHeaders headers = new MimeHeaders();
388395
headers.addValue(":method").setString(Method.POST);
@@ -393,8 +400,8 @@ protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer headersPay
393400
}
394401
headers.addValue(":path").setString(path);
395402
headers.addValue(":authority").setString("localhost:" + getPort());
396-
if (useExpectation) {
397-
headers.addValue("expect").setString("100-continue");
403+
if (expectation != null) {
404+
headers.addValue("expect").setString(expectation);
398405
}
399406
if (contentType != null) {
400407
headers.addValue("content-type").setString(contentType);

‎test/org/apache/coyote/http2/TestHttp2Section_8_1.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ public void setContinueHandlingResponsePolicy(ContinueResponseTiming policy) thr
152152

153153
@Test
154154
public void testSendAck() throws Exception {
155+
doTestSendAck("100-continue");
156+
}
157+
158+
159+
@Test
160+
public void testSendAckMixedCase() throws Exception {
161+
// RFC 9110, section 10.1.1: the Expect field value is case-insensitive
162+
doTestSendAck("100-Continue");
163+
}
164+
165+
166+
private void doTestSendAck(String expectation) throws Exception {
155167
// makes a request that expects a 100 Continue response and verifies
156168
// that the 100 Continue response is received. This does not check
157169
// that the correct ContinueHandlingResponsePolicy was followed, just
@@ -167,8 +179,8 @@ public void testSendAck() throws Exception {
167179
byte[] dataFrameHeader = new byte[9];
168180
ByteBuffer dataPayload = ByteBuffer.allocate(256);
169181

170-
buildPostRequest(headersFrameHeader, headersPayload, true, null, -1, "/simple", dataFrameHeader, dataPayload,
171-
null, false, 3);
182+
buildPostRequest(headersFrameHeader, headersPayload, expectation, null, -1, "/simple", dataFrameHeader,
183+
dataPayload, null, false, 3);
172184

173185
// Write the headers
174186
writeFrame(headersFrameHeader, headersPayload);

‎webapps/docs/changelog.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@
370370
that is in asynchronous mode are released if the connection thread
371371
raises a stream error for that stream. (markt)
372372
</fix>
373+
<fix>
374+
Treat the value of the <code>Expect</code> header as case insensitive
375+
for HTTP/2 requests, as required by RFC 9110, section 10.1.1, so that a
376+
<code>100 (Continue)</code> response is sent for
377+
<code>Expect: 100-Continue</code>. Pull request <pr>1263</pr> provided
378+
by Arturo Bernal.
379+
</fix>
373380
</changelog>
374381
</subsection>
375382
<subsection name="Jasper">

0 commit comments

Comments
 (0)