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 <gregw@webtide.com>
This commit is contained in:
parent
fa25d560b3
commit
1881683726
|
@ -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
|
||||
|
|
|
@ -93,7 +93,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* <li>
|
||||
* Is the Response {@code Content-Length} header present, and does its
|
||||
* value meet the minimum gzip size requirements?
|
||||
* <br> (Default: 16 bytes. see {@link GzipHandler#DEFAULT_MIN_GZIP_SIZE})
|
||||
* <br> (Default: 1024 bytes. see {@link GzipHandler#BREAK_EVEN_GZIP_SIZE})
|
||||
* </li>
|
||||
* <li>
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
|
@ -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<Arguments> scenarios()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<Arguments> scenarios()
|
||||
|
|
Loading…
Reference in New Issue