This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new ca29f6d8fd Revert compression refactoring ca29f6d8fd is described below commit ca29f6d8fdaf0a75b1d283405b92324c3c5dfa04 Author: remm <r...@apache.org> AuthorDate: Wed Oct 11 09:41:14 2023 +0200 Revert compression refactoring 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). --- java/org/apache/coyote/http11/Http11Processor.java | 13 +++++--- .../catalina/servlets/TestDefaultServlet.java | 38 ++++++++++++++++++++++ webapps/docs/changelog.xml | 8 +++++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java index 6b88365dbd..d3bc2a8f37 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -914,6 +914,12 @@ public class Http11Processor extends AbstractProcessor { 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) { @@ -950,11 +956,8 @@ public class Http11Processor extends AbstractProcessor { } } - // 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 diff --git a/test/org/apache/catalina/servlets/TestDefaultServlet.java b/test/org/apache/catalina/servlets/TestDefaultServlet.java index a3fdc0904c..889f7909c6 100644 --- a/test/org/apache/catalina/servlets/TestDefaultServlet.java +++ b/test/org/apache/catalina/servlets/TestDefaultServlet.java @@ -40,6 +40,7 @@ import org.apache.catalina.Wrapper; 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; @@ -86,6 +87,43 @@ public class TestDefaultServlet extends TomcatBaseTest { } + @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. */ diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 2d834a157b..23d01da0ce 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,14 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 9.0.82 (remm)" 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> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org