Skip to content

Commit

Permalink
Revert compression refactoring
Browse files Browse the repository at this point in the history
BZ 67670
Add test case to verify content-length is not present when using the
connector compression (also that checks DefaultServlet is working with
it).
  • Loading branch information
rmaucher committed Oct 11, 2023
1 parent 01559a2 commit 4729f7e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
13 changes: 8 additions & 5 deletions java/org/apache/coyote/http11/Http11Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,12 @@ protected final void prepareResponse() throws IOException {
prepareSendfile(outputFilters);
}

// Check for compression
boolean useCompression = false;
if (entityBody && sendfileData == null) {
useCompression = protocol.useCompression(request, response);
}

MimeHeaders headers = response.getMimeHeaders();
// A SC_NO_CONTENT response may include entity headers
if (entityBody || statusCode == HttpServletResponse.SC_NO_CONTENT) {
Expand Down Expand Up @@ -951,11 +957,8 @@ protected final void prepareResponse() throws IOException {
}
}

// Check for compression
if (entityBody && sendfileData == null) {
if (protocol.useCompression(request, response)) {
outputBuffer.addActiveFilter(outputFilters[Constants.GZIP_FILTER]);
}
if (useCompression) {
outputBuffer.addActiveFilter(outputFilters[Constants.GZIP_FILTER]);
}

// Add date header unless application has already set one (e.g. in a
Expand Down
38 changes: 38 additions & 0 deletions test/org/apache/catalina/servlets/TestDefaultServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.catalina.startup.SimpleHttpClient;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.descriptor.web.ErrorPage;
import org.apache.tomcat.websocket.server.WsContextListener;
Expand Down Expand Up @@ -86,6 +87,43 @@ public void testGetSpecials() throws Exception {

}

@Test
public void testDefaultCompression() throws Exception {

Tomcat tomcat = getTomcatInstance();
((AbstractHttp11Protocol<?>) tomcat.getConnector().getProtocolHandler()).setCompression("force");

File appDir = new File("test/webapp");

// app dir is relative to server home
Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default",
"org.apache.catalina.servlets.DefaultServlet");
defaultServlet.addInitParameter("fileEncoding", "ISO-8859-1");
ctxt.addServletMappingDecoded("/", "default");

ctxt.addMimeMapping("html", "text/html");

tomcat.start();

TestCompressedClient gzipClient = new TestCompressedClient(getPort());

gzipClient.reset();
gzipClient.setRequest(new String[] {
"GET /index.html HTTP/1.1" + CRLF +
"Host: localhost" + CRLF +
"Connection: Close" + CRLF +
"Accept-Encoding: gzip" + CRLF + CRLF });
gzipClient.connect();
gzipClient.processRequest();
Assert.assertTrue(gzipClient.isResponse200());
List<String> responseHeaders = gzipClient.getResponseHeaders();
Assert.assertTrue(responseHeaders.contains("Content-Encoding: gzip"));
for (String header : responseHeaders) {
Assert.assertFalse(header.startsWith("Content-Length: "));
}
}

/*
* Verify serving of gzipped resources from context root.
*/
Expand Down
8 changes: 8 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 10.1.15 (schultz)" rtext="in development">
<subsection name="Coyote">
<changelog>
<fix>
<bug>67670</bug>: Fix regression with HTTP compression after code
refactoring. (remm)
</fix>
</changelog>
</subsection>
<subsection name="jdbc-pool">
<changelog>
<fix>
Expand Down

0 comments on commit 4729f7e

Please sign in to comment.