Skip to content

Commit 4eaf880

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

3 files changed

Lines changed: 56 additions & 8 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.tomcat.util.http.parser.Host;
5353
import org.apache.tomcat.util.http.parser.HttpParser;
5454
import org.apache.tomcat.util.http.parser.Priority;
55+
import org.apache.tomcat.util.http.parser.TokenList;
5556
import org.apache.tomcat.util.net.ApplicationBufferHandler;
5657
import org.apache.tomcat.util.net.SocketEvent;
5758
import org.apache.tomcat.util.net.WriteBuffer;
@@ -552,8 +553,21 @@ public final void emitHeader(String name, String value) throws HpackException {
552553
break;
553554
}
554555
default: {
555-
if ("expect".equals(name) && "100-continue".equalsIgnoreCase(value)) {
556-
coyoteRequest.setExpectation(true);
556+
if ("expect".equals(name)) {
557+
// RFC 9110, section 10.1.1: the field value is a case-insensitive list of expectations
558+
if ("100-continue".equalsIgnoreCase(value)) {
559+
coyoteRequest.setExpectation(true);
560+
} else {
561+
Set<String> expectations = new HashSet<>();
562+
try {
563+
TokenList.parseTokenList(new StringReader(value), expectations);
564+
} catch (IOException ioe) {
565+
// Not possible with StringReader
566+
}
567+
if (expectations.contains("100-continue")) {
568+
coyoteRequest.setExpectation(true);
569+
}
570+
}
557571
}
558572
if (pseudoHeader) {
559573
headerException = new StreamException(

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

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

153153
@Test
154154
public void testSendAck() throws Exception {
155-
doTestSendAck("100-continue");
155+
doTestSendAck("100-continue", true);
156156
}
157157

158158

159159
@Test
160160
public void testSendAckMixedCase() throws Exception {
161161
// RFC 9110, section 10.1.1: the Expect field value is case-insensitive
162-
doTestSendAck("100-Continue");
162+
doTestSendAck("100-Continue", true);
163163
}
164164

165165

166-
private void doTestSendAck(String expectation) throws Exception {
166+
@Test
167+
public void testSendAckList() throws Exception {
168+
// RFC 9110, section 10.1.1: the Expect field value is a list of expectations
169+
doTestSendAck("foo, 100-continue", true);
170+
}
171+
172+
173+
@Test
174+
public void testSendAckListWithEmptyElements() throws Exception {
175+
doTestSendAck(",100-continue, ,foo", true);
176+
}
177+
178+
179+
@Test
180+
public void testNoAckForOtherExpectation() throws Exception {
181+
doTestSendAck("foo", false);
182+
}
183+
184+
185+
@Test
186+
public void testNoAckForContinueWithParameter() throws Exception {
187+
doTestSendAck("100-continue=1", false);
188+
}
189+
190+
191+
private void doTestSendAck(String expectation, boolean ack) throws Exception {
167192
// makes a request that expects a 100 Continue response and verifies
168193
// that the 100 Continue response is received. This does not check
169194
// that the correct ContinueHandlingResponsePolicy was followed, just
@@ -185,10 +210,13 @@ private void doTestSendAck(String expectation) throws Exception {
185210
// Write the headers
186211
writeFrame(headersFrameHeader, headersPayload);
187212

188-
parser.readFrame();
213+
if (ack) {
214+
parser.readFrame();
189215

190-
Assert.assertEquals("3-HeadersStart\n" + "3-Header-[:status]-[100]\n" + "3-HeadersEnd\n", output.getTrace());
191-
output.clearTrace();
216+
Assert.assertEquals("3-HeadersStart\n" + "3-Header-[:status]-[100]\n" + "3-HeadersEnd\n",
217+
output.getTrace());
218+
output.clearTrace();
219+
}
192220

193221
// Write the body
194222
writeFrame(dataFrameHeader, dataPayload);

‎webapps/docs/changelog.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@
377377
<code>Expect: 100-Continue</code>. Pull request <pr>1263</pr> provided
378378
by Arturo Bernal.
379379
</fix>
380+
<fix>
381+
Treat the value of the <code>Expect</code> header as a list of
382+
expectations for HTTP/2 requests, as required by RFC 9110, section
383+
10.1.1, so that a <code>100 (Continue)</code> response is sent when the
384+
list contains <code>100-continue</code>.
385+
</fix>
380386
</changelog>
381387
</subsection>
382388
<subsection name="Jasper">

0 commit comments

Comments
 (0)