Merged branch 'jetty-9.3.x' into 'master'.
This commit is contained in:
commit
f605397071
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.server.handler.gzip;
|
||||
|
||||
import static org.eclipse.jetty.http.GzipHttpContent.ETAG_GZIP_QUOTE;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
@ -47,7 +45,6 @@ import org.eclipse.jetty.util.URIUtil;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* A Handler that can dynamically GZIP compress responses. Unlike
|
||||
* previous and 3rd party GzipFilters, this mechanism works with asynchronously
|
||||
|
@ -71,7 +68,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
private boolean _syncFlush = false;
|
||||
|
||||
// non-static, as other GzipHandler instances may have different configurations
|
||||
private final ThreadLocal<Deflater> _deflater = new ThreadLocal<Deflater>();
|
||||
private final ThreadLocal<Deflater> _deflater = new ThreadLocal<>();
|
||||
|
||||
private final IncludeExclude<String> _agentPatterns=new IncludeExclude<>(RegexSet.class);
|
||||
private final IncludeExclude<String> _methods = new IncludeExclude<>();
|
||||
|
@ -398,6 +395,11 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
return _minGzipSize;
|
||||
}
|
||||
|
||||
protected HttpField getVaryField()
|
||||
{
|
||||
return _vary;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
|
@ -474,20 +476,21 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
String etag = baseRequest.getHttpFields().get(HttpHeader.IF_NONE_MATCH);
|
||||
if (etag!=null)
|
||||
{
|
||||
int i=etag.indexOf(ETAG_GZIP_QUOTE);
|
||||
int i=etag.indexOf(GzipHttpContent.ETAG_GZIP_QUOTE);
|
||||
if (i>0)
|
||||
{
|
||||
while (i>=0)
|
||||
{
|
||||
etag=etag.substring(0,i)+etag.substring(i+GzipHttpContent.ETAG_GZIP.length());
|
||||
i=etag.indexOf(ETAG_GZIP_QUOTE,i);
|
||||
i=etag.indexOf(GzipHttpContent.ETAG_GZIP_QUOTE,i);
|
||||
}
|
||||
baseRequest.getHttpFields().put(new HttpField(HttpHeader.IF_NONE_MATCH,etag));
|
||||
}
|
||||
}
|
||||
|
||||
// install interceptor and handle
|
||||
out.setInterceptor(new GzipHttpOutputInterceptor(this,_vary,baseRequest.getHttpChannel(),out.getInterceptor(),_syncFlush));
|
||||
out.setInterceptor(new GzipHttpOutputInterceptor(this,getVaryField(),baseRequest.getHttpChannel(),out.getInterceptor(),isSyncFlush()));
|
||||
|
||||
if (_handler!=null)
|
||||
_handler.handle(target,baseRequest, request, response);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.jetty.http.MimeTypes;
|
|||
import org.eclipse.jetty.http.PreEncodedHttpField;
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.eclipse.jetty.server.HttpOutput;
|
||||
import org.eclipse.jetty.server.Response;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.IteratingNestedCallback;
|
||||
|
@ -150,7 +151,8 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
protected void commit(ByteBuffer content, boolean complete, Callback callback)
|
||||
{
|
||||
// Are we excluding because of status?
|
||||
int sc = _channel.getResponse().getStatus();
|
||||
Response response = _channel.getResponse();
|
||||
int sc = response.getStatus();
|
||||
if (sc>0 && (sc<200 || sc==204 || sc==205 || sc>=300))
|
||||
{
|
||||
LOG.debug("{} exclude by status {}",this,sc);
|
||||
|
@ -160,7 +162,7 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
}
|
||||
|
||||
// Are we excluding because of mime-type?
|
||||
String ct = _channel.getResponse().getContentType();
|
||||
String ct = response.getContentType();
|
||||
if (ct!=null)
|
||||
{
|
||||
ct=MimeTypes.getContentTypeWithoutCharset(ct);
|
||||
|
@ -174,7 +176,7 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
}
|
||||
|
||||
// Has the Content-Encoding header already been set?
|
||||
String ce=_channel.getResponse().getHeader("Content-Encoding");
|
||||
String ce=response.getHeader("Content-Encoding");
|
||||
if (ce != null)
|
||||
{
|
||||
LOG.debug("{} exclude by content-encoding {}",this,ce);
|
||||
|
@ -187,10 +189,11 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
if (_state.compareAndSet(GZState.MIGHT_COMPRESS,GZState.COMMITTING))
|
||||
{
|
||||
// We are varying the response due to accept encoding header.
|
||||
HttpFields fields = _channel.getResponse().getHttpFields();
|
||||
fields.add(_vary);
|
||||
HttpFields fields = response.getHttpFields();
|
||||
if (_vary != null)
|
||||
fields.add(_vary);
|
||||
|
||||
long content_length = _channel.getResponse().getContentLength();
|
||||
long content_length = response.getContentLength();
|
||||
if (content_length<0 && complete)
|
||||
content_length=content.remaining();
|
||||
|
||||
|
@ -210,7 +213,7 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
|||
BufferUtil.fill(_buffer,GZIP_HEADER,0,GZIP_HEADER.length);
|
||||
|
||||
// Adjust headers
|
||||
_channel.getResponse().setContentLength(-1);
|
||||
response.setContentLength(-1);
|
||||
String etag=fields.get(HttpHeader.ETAG);
|
||||
if (etag!=null)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue