From 0fbb5078418f394af98485e86a7cabdded706761 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 14 Oct 2019 13:21:01 -0500 Subject: [PATCH 1/7] Issue #4191 - GzipHandler.minGzipSize cannot be lower then 23. Signed-off-by: Joakim Erdfelt --- .../server/handler/gzip/GzipHandler.java | 13 ++- .../jetty/servlet/GzipHandlerMinSizeTest.java | 102 ++++++++++++++++++ 2 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java index 45e54e1ccaf..2fb28f7679d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java @@ -26,7 +26,6 @@ import java.util.ListIterator; import java.util.Set; import java.util.regex.Pattern; import java.util.zip.Deflater; - import javax.servlet.DispatcherType; import javax.servlet.ServletContext; import javax.servlet.ServletException; @@ -156,7 +155,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory { public static final String GZIP = "gzip"; public static final String DEFLATE = "deflate"; - public static final int DEFAULT_MIN_GZIP_SIZE = 16; + public static final int DEFAULT_MIN_GZIP_SIZE = 23; private static final Logger LOG = Log.getLogger(GzipHandler.class); private static final HttpField X_CE_GZIP = new PreEncodedHttpField("X-Content-Encoding", "gzip"); private static final HttpField TE_CHUNKED = new PreEncodedHttpField(HttpHeader.TRANSFER_ENCODING, HttpHeaderValue.CHUNKED.asString()); @@ -946,13 +945,17 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory } /** - * Set the minimum response size to trigger dynamic compression + * Set the minimum response size to trigger dynamic compression. + *

+ * Sizes below 23 will result a compressed response that is larger then the + * original data. + *

* - * @param minGzipSize minimum response size in bytes + * @param minGzipSize minimum response size in bytes (not allowed to be lower then 23) */ public void setMinGzipSize(int minGzipSize) { - _minGzipSize = minGzipSize; + _minGzipSize = Math.max(DEFAULT_MIN_GZIP_SIZE, minGzipSize); } /** diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java new file mode 100644 index 00000000000..a8f326b7ea9 --- /dev/null +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java @@ -0,0 +1,102 @@ +package org.eclipse.jetty.servlet; + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.handler.gzip.GzipHandler; +import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.component.LifeCycle; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; + +public class GzipHandlerMinSizeTest +{ + private Server server; + private HttpClient client; + + @BeforeEach + public void startServerAndClient() throws Exception + { + server = new Server(); + ServerConnector connector = new ServerConnector(server); + connector.setPort(0); + server.addConnector(connector); + + GzipHandler gzipHandler = new GzipHandler(); + gzipHandler.setExcludedAgentPatterns(); + gzipHandler.setMinGzipSize(0); + + ServletContextHandler context = new ServletContextHandler(gzipHandler, "/"); + context.addServlet(VeryCompressibleContentServlet.class, "/content"); + gzipHandler.setHandler(context); + server.setHandler(gzipHandler); + + server.start(); + + client = new HttpClient(); + client.start(); + } + + @AfterEach + public void stopServerAndClient() + { + LifeCycle.stop(client); + LifeCycle.stop(server); + } + + @ParameterizedTest + @ValueSource(ints = {0, 1, 2, 3, 4, 5, 10, 15, 20, 21, 22, 23, 24, 25, 50, 100, 300, 500}) + public void testRequestSized(int size) throws Exception + { + URI uri = server.getURI().resolve("/content?size=" + size); + ContentResponse response = client.newRequest(uri) + .header(HttpHeader.ACCEPT_ENCODING, "gzip") + .send(); + + assertThat("Status Code", response.getStatus(), is(200)); + System.out.println(response.getHeaders()); + assertThat("Size Requested", response.getHeaders().getField("X-SizeRequested").getIntValue(), is(size)); + assertThat("Response Size", response.getHeaders().getField(HttpHeader.CONTENT_LENGTH).getIntValue(), lessThanOrEqualTo(size)); + } + + public static class VeryCompressibleContentServlet extends HttpServlet + { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException + { + resp.setContentType("text/plain"); + resp.setCharacterEncoding("utf-8"); + String sizeStr = req.getParameter("size"); + int size = 0; + if (!StringUtil.isBlank(sizeStr)) + { + size = Integer.parseInt(sizeStr); + } + resp.setHeader("X-SizeRequested", String.valueOf(size)); + if (size > 0) + { + byte[] buf = new byte[size]; + Arrays.fill(buf, (byte)'x'); + resp.getWriter().print(new String(buf, UTF_8)); + } + resp.getWriter().close(); + } + } +} From 9c49b03806016f7603e58b957b53a2e69efc02c3 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 15 Oct 2019 13:32:59 -0500 Subject: [PATCH 2/7] Adding missing license header Signed-off-by: Joakim Erdfelt --- .../jetty/servlet/GzipHandlerMinSizeTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java index a8f326b7ea9..155b8bc5045 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java @@ -1,3 +1,21 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + package org.eclipse.jetty.servlet; import java.io.IOException; From fa25d560b3654d7a38d9839c962a9819d3a44049 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 15 Oct 2019 13:52:39 -0500 Subject: [PATCH 3/7] Fixing typo Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java index 2fb28f7679d..6a29d1cf5c5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java @@ -947,7 +947,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory /** * Set the minimum response size to trigger dynamic compression. *

- * Sizes below 23 will result a compressed response that is larger then the + * Sizes below 23 will result a compressed response that is larger than the * original data. *

* From 18816837263aee299036aa57be9f6f617316dd05 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 16 Oct 2019 16:22:14 +1100 Subject: [PATCH 4/7] Issue #4191 Min GzipSize updates from review in absence of OP. Make break even size a warning rather than a hard limit. Signed-off-by: Greg Wilkins --- jetty-server/src/main/config/modules/gzip.mod | 2 +- .../eclipse/jetty/server/handler/gzip/GzipHandler.java | 10 ++++++---- ...SizeTest.java => GzipHandlerBreakEvenSizeTest.java} | 7 ++++--- .../server/handler/gzip/GzipContentLengthTest.java | 2 +- .../jetty/server/handler/gzip/GzipDefaultTest.java | 1 + .../eclipse/jetty/servlets/GzipFilterLayeredTest.java | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) rename jetty-servlet/src/test/java/org/eclipse/jetty/servlet/{GzipHandlerMinSizeTest.java => GzipHandlerBreakEvenSizeTest.java} (94%) diff --git a/jetty-server/src/main/config/modules/gzip.mod b/jetty-server/src/main/config/modules/gzip.mod index 24c045a37c4..13e209c5e99 100644 --- a/jetty-server/src/main/config/modules/gzip.mod +++ b/jetty-server/src/main/config/modules/gzip.mod @@ -15,7 +15,7 @@ etc/jetty-gzip.xml [ini-template] ## Minimum content length after which gzip is enabled -# jetty.gzip.minGzipSize=2048 +# jetty.gzip.minGzipSize=1024 ## Check whether a file with *.gz extension exists # jetty.gzip.checkGzExists=false diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java index 6a29d1cf5c5..e4673cf022f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java @@ -93,7 +93,7 @@ import org.eclipse.jetty.util.log.Logger; *
  • * Is the Response {@code Content-Length} header present, and does its * value meet the minimum gzip size requirements? - *
    (Default: 16 bytes. see {@link GzipHandler#DEFAULT_MIN_GZIP_SIZE}) + *
    (Default: 1024 bytes. see {@link GzipHandler#BREAK_EVEN_GZIP_SIZE}) *
  • *
  • * Is the Request {@code Accept} header present and does it contain the @@ -155,7 +155,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory { public static final String GZIP = "gzip"; public static final String DEFLATE = "deflate"; - public static final int DEFAULT_MIN_GZIP_SIZE = 23; + public static final int BREAK_EVEN_GZIP_SIZE = 23; private static final Logger LOG = Log.getLogger(GzipHandler.class); private static final HttpField X_CE_GZIP = new PreEncodedHttpField("X-Content-Encoding", "gzip"); private static final HttpField TE_CHUNKED = new PreEncodedHttpField(HttpHeader.TRANSFER_ENCODING, HttpHeaderValue.CHUNKED.asString()); @@ -164,7 +164,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory private int _poolCapacity = -1; private DeflaterPool _deflaterPool = null; - private int _minGzipSize = DEFAULT_MIN_GZIP_SIZE; + private int _minGzipSize = 1024; private int _compressionLevel = Deflater.DEFAULT_COMPRESSION; /** * @deprecated feature will be removed in Jetty 10.x, with no replacement. @@ -955,7 +955,9 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory */ public void setMinGzipSize(int minGzipSize) { - _minGzipSize = Math.max(DEFAULT_MIN_GZIP_SIZE, minGzipSize); + if (minGzipSize < BREAK_EVEN_GZIP_SIZE) + LOG.warn("minGzipSize {} is less break even size {}", minGzipSize, BREAK_EVEN_GZIP_SIZE); + _minGzipSize = Math.max(0, minGzipSize); } /** diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerBreakEvenSizeTest.java similarity index 94% rename from jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java rename to jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerBreakEvenSizeTest.java index 155b8bc5045..70771c53e2c 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerMinSizeTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/GzipHandlerBreakEvenSizeTest.java @@ -44,7 +44,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; -public class GzipHandlerMinSizeTest +public class GzipHandlerBreakEvenSizeTest { private Server server; private HttpClient client; @@ -89,9 +89,10 @@ public class GzipHandlerMinSizeTest .send(); assertThat("Status Code", response.getStatus(), is(200)); - System.out.println(response.getHeaders()); assertThat("Size Requested", response.getHeaders().getField("X-SizeRequested").getIntValue(), is(size)); - assertThat("Response Size", response.getHeaders().getField(HttpHeader.CONTENT_LENGTH).getIntValue(), lessThanOrEqualTo(size)); + + if (size > GzipHandler.BREAK_EVEN_GZIP_SIZE) + assertThat("Response Size", response.getHeaders().getField(HttpHeader.CONTENT_LENGTH).getIntValue(), lessThanOrEqualTo(size)); } public static class VeryCompressibleContentServlet extends HttpServlet diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java index ffc085c5beb..0bb35a81f50 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java @@ -54,7 +54,7 @@ public class GzipContentLengthTest private static final int LARGE = defaultHttp.getOutputBufferSize() * 8; private static final int MEDIUM = defaultHttp.getOutputBufferSize(); private static final int SMALL = defaultHttp.getOutputBufferSize() / 4; - private static final int TINY = GzipHandler.DEFAULT_MIN_GZIP_SIZE / 2; + private static final int TINY = GzipHandler.BREAK_EVEN_GZIP_SIZE / 2; private static final boolean EXPECT_COMPRESSED = true; public static Stream scenarios() diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java index 5f0a14c44cf..060b1019a9c 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java @@ -468,6 +468,7 @@ public class GzipDefaultTest tester.setContentServlet(HttpContentTypeWithEncoding.class); tester.getGzipHandler().addIncludedMimeTypes("text/plain"); tester.getGzipHandler().setExcludedAgentPatterns(); + tester.getGzipHandler().setMinGzipSize(16); try { tester.start(); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java index c5fa7386461..04a376da67a 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java @@ -61,7 +61,7 @@ public class GzipFilterLayeredTest private static final HttpConfiguration defaultHttp = new HttpConfiguration(); private static final int LARGE = defaultHttp.getOutputBufferSize() * 8; private static final int SMALL = defaultHttp.getOutputBufferSize() / 4; - private static final int TINY = GzipHandler.DEFAULT_MIN_GZIP_SIZE / 2; + private static final int TINY = GzipHandler.BREAK_EVEN_GZIP_SIZE / 2; private static final boolean EXPECT_COMPRESSED = true; public static Stream scenarios() From b7c93842918e043ba282d1d8dc27bd7603f7c3bd Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 16 Oct 2019 18:16:39 +1100 Subject: [PATCH 5/7] fixed test Signed-off-by: Greg Wilkins --- .../org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java index 3defcfcf99f..09fb685ae65 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java @@ -88,6 +88,7 @@ public class IncludedGzipTest tester.getContext().addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/"); GzipHandler gzipHandler = new GzipHandler(); + gzipHandler.setMinGzipSize(16); tester.getContext().insertHandler(gzipHandler); tester.start(); } From 031df2bd2ea4fde2ed11b80aff9737e4abc5b0f6 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 16 Oct 2019 18:19:22 +1100 Subject: [PATCH 6/7] simplified javadoc Signed-off-by: Greg Wilkins --- .../org/eclipse/jetty/server/handler/gzip/GzipHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java index e4673cf022f..6213fcf12e8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java @@ -92,8 +92,7 @@ import org.eclipse.jetty.util.log.Logger; *
  • *
  • * Is the Response {@code Content-Length} header present, and does its - * value meet the minimum gzip size requirements? - *
    (Default: 1024 bytes. see {@link GzipHandler#BREAK_EVEN_GZIP_SIZE}) + * value meet the minimum gzip size requirements (default 1024 bytes)? *
  • *
  • * Is the Request {@code Accept} header present and does it contain the From 7cc552013eb4d05cb603ba0bc85d176c97957cd4 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 16 Oct 2019 22:07:51 +1100 Subject: [PATCH 7/7] Issue #4191 Min GzipSize updates from review from OP. reverted static DEFAULT_MIN_GZIP_SIZE Signed-off-by: Greg Wilkins --- jetty-server/src/main/config/modules/gzip.mod | 2 +- .../jetty/server/handler/gzip/GzipHandler.java | 11 ++++++----- .../server/handler/gzip/GzipContentLengthTest.java | 2 +- .../jetty/server/handler/gzip/GzipDefaultTest.java | 1 - .../jetty/server/handler/gzip/IncludedGzipTest.java | 1 - .../eclipse/jetty/servlets/GzipFilterLayeredTest.java | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/jetty-server/src/main/config/modules/gzip.mod b/jetty-server/src/main/config/modules/gzip.mod index 13e209c5e99..96be4bb9c01 100644 --- a/jetty-server/src/main/config/modules/gzip.mod +++ b/jetty-server/src/main/config/modules/gzip.mod @@ -15,7 +15,7 @@ etc/jetty-gzip.xml [ini-template] ## Minimum content length after which gzip is enabled -# jetty.gzip.minGzipSize=1024 +# jetty.gzip.minGzipSize=32 ## Check whether a file with *.gz extension exists # jetty.gzip.checkGzExists=false diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java index 94339b38546..c175d7e85fc 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java @@ -92,7 +92,7 @@ import org.eclipse.jetty.util.log.Logger; *
  • *
  • * Is the Response {@code Content-Length} header present, and does its - * value meet the minimum gzip size requirements (default 1024 bytes)? + * value meet the minimum gzip size requirements (default 32 bytes)? *
  • *
  • * Is the Request {@code Accept} header present and does it contain the @@ -154,6 +154,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory { public static final String GZIP = "gzip"; public static final String DEFLATE = "deflate"; + public static final int DEFAULT_MIN_GZIP_SIZE = 32; public static final int BREAK_EVEN_GZIP_SIZE = 23; private static final Logger LOG = Log.getLogger(GzipHandler.class); private static final HttpField X_CE_GZIP = new PreEncodedHttpField("X-Content-Encoding", "gzip"); @@ -163,7 +164,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory private int _poolCapacity = -1; private DeflaterPool _deflaterPool = null; - private int _minGzipSize = 1024; + private int _minGzipSize = DEFAULT_MIN_GZIP_SIZE; private int _compressionLevel = Deflater.DEFAULT_COMPRESSION; /** * @deprecated feature will be removed in Jetty 10.x, with no replacement. @@ -949,16 +950,16 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory /** * Set the minimum response size to trigger dynamic compression. *

    - * Sizes below 23 will result a compressed response that is larger than the + * Sizes below {@link #BREAK_EVEN_GZIP_SIZE} will result a compressed response that is larger than the * original data. *

    * - * @param minGzipSize minimum response size in bytes (not allowed to be lower then 23) + * @param minGzipSize minimum response size in bytes (not allowed to be lower then {@link #BREAK_EVEN_GZIP_SIZE}) */ public void setMinGzipSize(int minGzipSize) { if (minGzipSize < BREAK_EVEN_GZIP_SIZE) - LOG.warn("minGzipSize {} is less break even size {}", minGzipSize, BREAK_EVEN_GZIP_SIZE); + LOG.warn("minGzipSize of {} is inefficient for short content, break even is size {}", minGzipSize, BREAK_EVEN_GZIP_SIZE); _minGzipSize = Math.max(0, minGzipSize); } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java index 0bb35a81f50..ffc085c5beb 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipContentLengthTest.java @@ -54,7 +54,7 @@ public class GzipContentLengthTest private static final int LARGE = defaultHttp.getOutputBufferSize() * 8; private static final int MEDIUM = defaultHttp.getOutputBufferSize(); private static final int SMALL = defaultHttp.getOutputBufferSize() / 4; - private static final int TINY = GzipHandler.BREAK_EVEN_GZIP_SIZE / 2; + private static final int TINY = GzipHandler.DEFAULT_MIN_GZIP_SIZE / 2; private static final boolean EXPECT_COMPRESSED = true; public static Stream scenarios() diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java index 060b1019a9c..5f0a14c44cf 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java @@ -468,7 +468,6 @@ public class GzipDefaultTest tester.setContentServlet(HttpContentTypeWithEncoding.class); tester.getGzipHandler().addIncludedMimeTypes("text/plain"); tester.getGzipHandler().setExcludedAgentPatterns(); - tester.getGzipHandler().setMinGzipSize(16); try { tester.start(); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java index 09fb685ae65..3defcfcf99f 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/IncludedGzipTest.java @@ -88,7 +88,6 @@ public class IncludedGzipTest tester.getContext().addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/"); GzipHandler gzipHandler = new GzipHandler(); - gzipHandler.setMinGzipSize(16); tester.getContext().insertHandler(gzipHandler); tester.start(); } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java index 04a376da67a..c5fa7386461 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterLayeredTest.java @@ -61,7 +61,7 @@ public class GzipFilterLayeredTest private static final HttpConfiguration defaultHttp = new HttpConfiguration(); private static final int LARGE = defaultHttp.getOutputBufferSize() * 8; private static final int SMALL = defaultHttp.getOutputBufferSize() / 4; - private static final int TINY = GzipHandler.BREAK_EVEN_GZIP_SIZE / 2; + private static final int TINY = GzipHandler.DEFAULT_MIN_GZIP_SIZE / 2; private static final boolean EXPECT_COMPRESSED = true; public static Stream scenarios()