Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2016-01-14 22:27:09 -0500
committerGreg Wilkins2016-01-14 22:27:09 -0500
commitd41c0bba65d7b95ef5d80270b84010e67c5f94c8 (patch)
tree672317665432094d0f76cf21d9dbe1ebfe7ab9ae
parentfa374cd8994e288dce23089f1890edc5c1ca5f34 (diff)
downloadorg.eclipse.jetty.project-d41c0bba65d7b95ef5d80270b84010e67c5f94c8.tar.gz
org.eclipse.jetty.project-d41c0bba65d7b95ef5d80270b84010e67c5f94c8.tar.xz
org.eclipse.jetty.project-d41c0bba65d7b95ef5d80270b84010e67c5f94c8.zip
471171 - Support SYNC_FLUSH in GzipHandler
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java24
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHttpOutputInterceptor.java14
2 files changed, 31 insertions, 7 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 05a16a46fc..5200eff13b 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
@@ -68,6 +68,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
private int _minGzipSize=DEFAULT_MIN_GZIP_SIZE;
private int _compressionLevel=Deflater.DEFAULT_COMPRESSION;
private boolean _checkGzExists = true;
+ private boolean _syncFlush = false;
// non-static, as other GzipHandler instances may have different configurations
private final ThreadLocal<Deflater> _deflater = new ThreadLocal<Deflater>();
@@ -177,6 +178,27 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
/* ------------------------------------------------------------ */
/**
+ * @return True if {@link Deflater#SYNC_FLUSH} is used, else {@link Deflater#NO_FLUSH}
+ */
+ public boolean isSyncFlush()
+ {
+ return _syncFlush;
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
+ * <p>Set the {@link Deflater} flush mode to use. {@link Deflater#SYNC_FLUSH}
+ * should be used if the application wishes to stream the data, but this may
+ * hurt compression performance.
+ * @param syncFlush True if {@link Deflater#SYNC_FLUSH} is used, else {@link Deflater#NO_FLUSH}
+ */
+ public void setSyncFlush(boolean syncFlush)
+ {
+ _syncFlush = syncFlush;
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
* Add included mime types. Inclusion takes precedence over
* exclusion.
* @param types The mime types to include (without charset or other parameters)
@@ -432,7 +454,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
}
// install interceptor and handle
- out.setInterceptor(new GzipHttpOutputInterceptor(this,_vary,baseRequest.getHttpChannel(),out.getInterceptor()));
+ out.setInterceptor(new GzipHttpOutputInterceptor(this,_vary,baseRequest.getHttpChannel(),out.getInterceptor(),_syncFlush));
if (_handler!=null)
_handler.handle(target,baseRequest, request, response);
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHttpOutputInterceptor.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHttpOutputInterceptor.java
index c7fc799cce..f717c2656a 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHttpOutputInterceptor.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHttpOutputInterceptor.java
@@ -56,27 +56,29 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
private final HttpChannel _channel;
private final HttpField _vary;
private final int _bufferSize;
+ private final boolean _syncFlush;
private Deflater _deflater;
private ByteBuffer _buffer;
- public GzipHttpOutputInterceptor(GzipFactory factory, HttpChannel channel, HttpOutput.Interceptor next)
+ public GzipHttpOutputInterceptor(GzipFactory factory, HttpChannel channel, HttpOutput.Interceptor next,boolean syncFlush)
{
- this(factory,VARY_ACCEPT_ENCODING_USER_AGENT,channel.getHttpConfiguration().getOutputBufferSize(),channel,next);
+ this(factory,VARY_ACCEPT_ENCODING_USER_AGENT,channel.getHttpConfiguration().getOutputBufferSize(),channel,next,syncFlush);
}
- public GzipHttpOutputInterceptor(GzipFactory factory, HttpField vary, HttpChannel channel, HttpOutput.Interceptor next)
+ public GzipHttpOutputInterceptor(GzipFactory factory, HttpField vary, HttpChannel channel, HttpOutput.Interceptor next,boolean syncFlush)
{
- this(factory,vary,channel.getHttpConfiguration().getOutputBufferSize(),channel,next);
+ this(factory,vary,channel.getHttpConfiguration().getOutputBufferSize(),channel,next,syncFlush);
}
- public GzipHttpOutputInterceptor(GzipFactory factory, HttpField vary, int bufferSize, HttpChannel channel, HttpOutput.Interceptor next)
+ public GzipHttpOutputInterceptor(GzipFactory factory, HttpField vary, int bufferSize, HttpChannel channel, HttpOutput.Interceptor next,boolean syncFlush)
{
_factory=factory;
_channel=channel;
_interceptor=next;
_vary=vary;
_bufferSize=bufferSize;
+ _syncFlush=syncFlush;
}
public HttpOutput.Interceptor getNextInterceptor()
@@ -353,7 +355,7 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
int len=_buffer.capacity()-_buffer.limit() - (_last?8:0);
if (len>0)
{
- int produced=_deflater.deflate(_buffer.array(),off,len,Deflater.NO_FLUSH);
+ int produced=_deflater.deflate(_buffer.array(),off,len,_syncFlush?Deflater.SYNC_FLUSH:Deflater.NO_FLUSH);
_buffer.limit(_buffer.limit()+produced);
}
boolean finished=_deflater.finished();

Back to the top