Remove support for the identity T-E header value · apache/tomcat@eee0d02 · GitHub
Skip to content

Commit

Permalink
Remove support for the identity T-E header value
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jun 8, 2021
1 parent 5be9cff commit eee0d02
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 31 deletions.
8 changes: 2 additions & 6 deletions java/org/apache/coyote/http11/Http11Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,8 @@ private void addInputFilter(InputFilter[] inputFilters, String encodingName) {

// Parsing trims and converts to lower case.

if (encodingName.equals("identity")) {
// Skip
} else if (encodingName.equals("chunked")) {
inputBuffer.addActiveFilter
(inputFilters[Constants.CHUNKED_FILTER]);
if (encodingName.equals("chunked")) {
inputBuffer.addActiveFilter(inputFilters[Constants.CHUNKED_FILTER]);
contentDelimitation = true;
} else {
for (int i = pluggableFilterIndex; i < inputFilters.length; i++) {
Expand Down Expand Up @@ -759,7 +756,6 @@ private void prepareRequest() throws IOException {
List<String> encodingNames = new ArrayList<>();
if (TokenList.parseTokenList(headers.values("transfer-encoding"), encodingNames)) {
for (String encodingName : encodingNames) {
// "identity" codings are ignored
addInputFilter(inputFilters, encodingName);
}
} else {
Expand Down
95 changes: 70 additions & 25 deletions test/org/apache/coyote/http11/TestHttp11Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,31 +253,6 @@ private void doTestWithTEChunked(boolean withCL) throws Exception {
}


@Test
public void testWithTEIdentity() throws Exception {
getTomcatInstanceTestWebapp(false, true);

String request =
"POST /test/echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
"Host: any" + SimpleHttpClient.CRLF +
"Transfer-encoding: identity" + SimpleHttpClient.CRLF +
"Content-Length: 9" + SimpleHttpClient.CRLF +
"Content-Type: application/x-www-form-urlencoded" +
SimpleHttpClient.CRLF +
"Connection: close" + SimpleHttpClient.CRLF +
SimpleHttpClient.CRLF +
"test=data";

Client client = new Client(getPort());
client.setRequest(new String[] {request});

client.connect();
client.processRequest();
Assert.assertTrue(client.isResponse200());
Assert.assertTrue(client.getResponseBody().contains("test - data"));
}


@Test
public void testWithTESavedRequest() throws Exception {
getTomcatInstanceTestWebapp(false, true);
Expand Down Expand Up @@ -1859,4 +1834,74 @@ public void onError(Throwable throwable) {
// NO-OP
}
}


@Test
public void testTEHeaderUnknown01() throws Exception {
doTestTEHeaderUnknown("identity");
}


@Test
public void testTEHeaderUnknown02() throws Exception {
doTestTEHeaderUnknown("identity, chunked");
}


@Test
public void testTEHeaderUnknown03() throws Exception {
doTestTEHeaderUnknown("unknown, chunked");
}


@Test
public void testTEHeaderUnknown04() throws Exception {
doTestTEHeaderUnknown("void");
}


@Test
public void testTEHeaderUnknown05() throws Exception {
doTestTEHeaderUnknown("void, chunked");
}


@Test
public void testTEHeaderUnknown06() throws Exception {
doTestTEHeaderUnknown("void, identity");
}


@Test
public void testTEHeaderUnknown07() throws Exception {
doTestTEHeaderUnknown("identity, void");
}


private void doTestTEHeaderUnknown(String headerValue) throws Exception {
Tomcat tomcat = getTomcatInstance();

// No file system docBase required
Context ctx = tomcat.addContext("", null);

// Add servlet
Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet(false));
ctx.addServletMappingDecoded("/foo", "TesterServlet");

tomcat.start();

String request =
"GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
"Host: localhost:" + getPort() + SimpleHttpClient.CRLF +
"Transfer-Encoding: " + headerValue + SimpleHttpClient.CRLF +
SimpleHttpClient.CRLF;

Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] {request});

client.connect();
client.processRequest(false);

Assert.assertTrue(client.isResponse501());
}
}
6 changes: 6 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@
the empty token is at the start, middle or end of the list of tokens.
(markt)
</fix>
<fix>
Remove support for the <code>identity</code> transfer encoding. The
inclusion of this encoding in RFC 2616 was an error that was corrected
in 2001. Requests using this transfer encoding will now receive a 501
response. (markt)
</fix>
</changelog>
</subsection>
<subsection name="Jasper">
Expand Down

0 comments on commit eee0d02

Please sign in to comment.