From 7cc552013eb4d05cb603ba0bc85d176c97957cd4 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 16 Oct 2019 22:07:51 +1100 Subject: [PATCH] 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()