Skip to content

Commit e5e85ee

Browse files
authored
Fix BZ 69918 - Ensure request parameters are correctly parsed for HTTP/2 requests when the content-length header is not set.
1 parent 61cbe49 commit e5e85ee

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

java/org/apache/catalina/connector/Request.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,8 @@ protected void doParseParameters() {
28762876
return;
28772877
}
28782878
parameters.processParameters(formData, 0, len);
2879-
} else if ("chunked".equalsIgnoreCase(coyoteRequest.getHeader("transfer-encoding"))) {
2879+
} else if (coyoteRequest.protocol().equals("HTTP/2.0")
2880+
|| "chunked".equalsIgnoreCase(coyoteRequest.getHeader("transfer-encoding"))) {
28802881
byte[] formData = null;
28812882
try {
28822883
formData = readChunkedPostBody();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.coyote.http2;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
23+
import org.apache.catalina.connector.Request;
24+
25+
public class TestHttp2RequestParameters extends Http2TestBase {
26+
/**
27+
* Test case for https://bz.apache.org/bugzilla/show_bug.cgi?id=69918 POST parameters are not returned from a call
28+
* to any of the {@link Request} getParameterXXX() methods if the request is HTTP/2 and the
29+
* content-length header is not set.
30+
*/
31+
@Test
32+
public void testBug69918() throws Exception {
33+
http2Connect();
34+
35+
sendParameterPostRequest(3, null, "a=1&b=2", -1, false);
36+
output.setTraceBody(true);
37+
38+
boolean foundBody = false;
39+
while (parser.readFrame()) {
40+
String trace = output.getTrace();
41+
if (trace.contains("3-Body-2")) {
42+
foundBody = true;
43+
} else if (trace.contains("3-Body-0")) {
44+
Assert.fail("Parameter count was 0. Trace: " + trace);
45+
}
46+
if (trace.contains("3-EndOfStream")) {
47+
break;
48+
}
49+
}
50+
Assert.assertTrue("Parameter count should be 2, trace: " + output.getTrace(), foundBody);
51+
}
52+
}

webapps/docs/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@
201201
Pull request <pr>923</pr>: Avoid adding multiple CSRF tokens to a URL in
202202
the <code>CsrfPreventionFilter</code>. (schultz)
203203
</fix>
204+
<fix>
205+
<bug>69918</bug>: Ensure request parameters are correctly parsed for HTTP/2 requests
206+
when the content-length header is not set. (dsoumis)
207+
</fix>
204208
</changelog>
205209
</subsection>
206210
<subsection name="Coyote">

0 commit comments

Comments
 (0)