Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions java/org/apache/coyote/http2/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -552,8 +553,21 @@ public final void emitHeader(String name, String value) throws HpackException {
break;
}
default: {
if ("expect".equals(name) && "100-continue".equals(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<String> 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(
Expand Down
11 changes: 9 additions & 2 deletions test/org/apache/coyote/http2/Http2TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
50 changes: 45 additions & 5 deletions test/org/apache/coyote/http2/TestHttp2Section_8_1.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,43 @@ public void setContinueHandlingResponsePolicy(ContinueResponseTiming policy) thr

@Test
public void testSendAck() throws Exception {
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", true);
}


@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
Expand All @@ -167,16 +204,19 @@ 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);

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);
Expand Down
14 changes: 14 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,20 @@
that is in asynchronous mode are released if the connection thread
raises a stream error for that stream. (markt)
</fix>
<fix>
Treat the value of the <code>Expect</code> header as case insensitive
for HTTP/2 requests, as required by RFC 9110, section 10.1.1, so that a
<code>100 (Continue)</code> response is sent for
<code>Expect: 100-Continue</code>. Pull request <pr>1263</pr> provided
by Arturo Bernal.
</fix>
<fix>
Treat the value of the <code>Expect</code> header as a list of
expectations for HTTP/2 requests, as required by RFC 9110, section
10.1.1, so that a <code>100 (Continue)</code> response is sent when the
list contains <code>100-continue</code>. Pull request <pr>1265</pr>
provided by Arturo Bernal.
</fix>
</changelog>
</subsection>
<subsection name="Jasper">
Expand Down
Loading