Issue #4191 Min GzipSize

updates from review from OP.
reverted static DEFAULT_MIN_GZIP_SIZE

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-10-16 22:07:51 +11:00
parent 2ee874a8ac
commit 7cc552013e
6 changed files with 9 additions and 10 deletions

View File

@ -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

View File

@ -92,7 +92,7 @@ import org.eclipse.jetty.util.log.Logger;
* </li>
* <li>
* 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)?
* </li>
* <li>
* 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.
* <p>
* 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.
* </p>
*
* @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);
}

View File

@ -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<Arguments> scenarios()

View File

@ -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();

View File

@ -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();
}

View File

@ -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<Arguments> scenarios()