Merge branch 'jetty-9.4.x' into jetty-9.4.x-ewyk
This commit is contained in:
commit
69003d3dd9
|
@ -13,7 +13,7 @@
|
|||
<name>Jetty :: GCloud</name>
|
||||
|
||||
<properties>
|
||||
<gcloud.version>0.9.4-beta</gcloud.version>
|
||||
<gcloud.version>0.10.0-beta</gcloud.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
|
|
@ -73,7 +73,7 @@ public class HttpStatus
|
|||
public final static int REQUESTED_RANGE_NOT_SATISFIABLE_416 = 416;
|
||||
public final static int RANGE_NOT_SATISFIABLE_416 = 416;
|
||||
public final static int EXPECTATION_FAILED_417 = 417;
|
||||
public final static int IM_A_TEAPOT_418 = 417;
|
||||
public final static int IM_A_TEAPOT_418 = 418;
|
||||
public final static int ENHANCE_YOUR_CALM_420 = 420;
|
||||
public final static int MISDIRECTED_REQUEST_421 = 421;
|
||||
public final static int UNPROCESSABLE_ENTITY_422 = 422;
|
||||
|
@ -153,7 +153,7 @@ public class HttpStatus
|
|||
UNSUPPORTED_MEDIA_TYPE(UNSUPPORTED_MEDIA_TYPE_415, "Unsupported Media Type"),
|
||||
RANGE_NOT_SATISFIABLE(RANGE_NOT_SATISFIABLE_416, "Range Not Satisfiable"),
|
||||
EXPECTATION_FAILED(EXPECTATION_FAILED_417, "Expectation Failed"),
|
||||
IM_A_TEAPOT(IM_A_TEAPOT_418, "Im a Teapot"),
|
||||
IM_A_TEAPOT(IM_A_TEAPOT_418, "I'm a Teapot"),
|
||||
ENHANCE_YOUR_CALM(ENHANCE_YOUR_CALM_420, "Enhance your Calm"),
|
||||
MISDIRECTED_REQUEST(MISDIRECTED_REQUEST_421, "Misdirected Request"),
|
||||
UNPROCESSABLE_ENTITY(UNPROCESSABLE_ENTITY_422, "Unprocessable Entity"),
|
||||
|
|
|
@ -32,6 +32,14 @@ public class HttpStatusCodeTest
|
|||
assertNull("Invalid code: 190", HttpStatus.getCode(190));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testImATeapot()
|
||||
{
|
||||
assertEquals("I'm a Teapot", HttpStatus.getMessage(418));
|
||||
assertEquals("Expectation Failed", HttpStatus.getMessage(417));
|
||||
}
|
||||
|
||||
public void testHttpMethod()
|
||||
{
|
||||
assertEquals("GET",HttpMethod.GET.toString());
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/></Set>
|
||||
<Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel" default="-1"/></Set>
|
||||
<Set name="inflateBufferSize"><Property name="jetty.gzip.inflateBufferSize" default="0"/></Set>
|
||||
<Set name="syncFlush"><Property name="jetty.gzip.syncFlush" default="false" /></Set>
|
||||
|
||||
<Set name="excludedAgentPatterns">
|
||||
<Array type="String">
|
||||
|
@ -23,37 +24,34 @@
|
|||
</Array>
|
||||
</Set>
|
||||
|
||||
<Set name="includedMethodList"><Property name="jetty.gzip.includedMethodList" default="GET" /></Set>
|
||||
<Set name="excludedMethodList"><Property name="jetty.gzip.excludedMethodList" default="" /></Set>
|
||||
|
||||
<!--
|
||||
<Set name="includedMethods">
|
||||
<Array type="String">
|
||||
<Item>GET</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
|
||||
<!--
|
||||
<Set name="includedPaths">
|
||||
<Array type="String">
|
||||
<Item>/*</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
-->
|
||||
|
||||
<!--
|
||||
<Set name="excludedPaths">
|
||||
<Array type="String">
|
||||
<Item>*.gz</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
-->
|
||||
|
||||
<!--
|
||||
<Call name="addIncludedMimeTypes">
|
||||
<Arg><Array type="String">
|
||||
<Item>some/type</Item>
|
||||
</Array></Arg>
|
||||
</Call>
|
||||
-->
|
||||
|
||||
<!--
|
||||
<Call name="addExcludedMimeTypes">
|
||||
<Arg><Array type="String">
|
||||
<Item>some/type</Item>
|
||||
|
|
|
@ -26,3 +26,9 @@ etc/jetty-gzip.xml
|
|||
|
||||
## Inflate request buffer size, or 0 for no request inflation
|
||||
# jetty.gzip.inflateBufferSize=0
|
||||
|
||||
## Comma separated list of included methods
|
||||
# jetty.gzip.includedMethodList=GET
|
||||
|
||||
## Comma separated list of excluded methods
|
||||
# jetty.gzip.excludedMethodList=
|
||||
|
|
|
@ -129,7 +129,7 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
|||
* <li>call the {@link #getDefaultConnectionFactory()} {@link ConnectionFactory#newConnection(Connector, org.eclipse.jetty.io.EndPoint)}
|
||||
* method to create a new Connection instance.</li>
|
||||
* </ol>
|
||||
* The default number of acceptor tasks is the minimum of 1 and half the number of available CPUs. Having more acceptors may reduce
|
||||
* The default number of acceptor tasks is the minimum of 1 and the number of available CPUs divided by 8. Having more acceptors may reduce
|
||||
* the latency for servers that see a high rate of new connections (eg HTTP/1.0 without keep-alive). Typically the default is
|
||||
* sufficient for modern persistent protocols (HTTP/1.1, HTTP/2 etc.)
|
||||
*/
|
||||
|
|
|
@ -225,29 +225,54 @@ public class Dispatcher implements RequestDispatcher
|
|||
return String.format("Dispatcher@0x%x{%s,%s}",hashCode(),_named,_uri);
|
||||
}
|
||||
|
||||
private void commitResponse(ServletResponse response, Request baseRequest) throws IOException
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void commitResponse(ServletResponse response, Request baseRequest) throws IOException, ServletException
|
||||
{
|
||||
if (baseRequest.getResponse().isWriting())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try closing Writer first (based on knowledge in Response obj)
|
||||
response.getWriter().close();
|
||||
}
|
||||
catch (IllegalStateException e)
|
||||
catch (IllegalStateException e1)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try closing OutputStream as alternate route
|
||||
// This path is possible due to badly behaving Response wrappers
|
||||
response.getOutputStream().close();
|
||||
}
|
||||
catch(IllegalStateException e2)
|
||||
{
|
||||
ServletException servletException = new ServletException("Unable to commit the response", e2);
|
||||
servletException.addSuppressed(e1);
|
||||
throw servletException;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try closing OutputStream first (based on knowledge in Response obj)
|
||||
response.getOutputStream().close();
|
||||
}
|
||||
catch (IllegalStateException e)
|
||||
catch (IllegalStateException e1)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try closing Writer as alternate route
|
||||
// This path is possible due to badly behaving Response wrappers
|
||||
response.getWriter().close();
|
||||
}
|
||||
catch(IllegalStateException e2)
|
||||
{
|
||||
ServletException servletException = new ServletException("Unable to commit the response", e2);
|
||||
servletException.addSuppressed(e1);
|
||||
throw servletException;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,7 @@ public class Response implements HttpServletResponse
|
|||
|
||||
private enum EncodingFrom { NOT_SET, INFERRED, SET_LOCALE, SET_CONTENT_TYPE, SET_CHARACTER_ENCODING };
|
||||
private static final EnumSet<EncodingFrom> __localeOverride = EnumSet.of(EncodingFrom.NOT_SET,EncodingFrom.INFERRED);
|
||||
private static final EnumSet<EncodingFrom> __explicitCharset = EnumSet.of(EncodingFrom.SET_LOCALE,EncodingFrom.SET_CHARACTER_ENCODING);
|
||||
|
||||
|
||||
public Response(HttpChannel channel, HttpOutput out)
|
||||
|
@ -1424,12 +1425,21 @@ public class Response implements HttpServletResponse
|
|||
|
||||
HttpField ct=content.getContentType();
|
||||
if (ct!=null)
|
||||
{
|
||||
if (_characterEncoding!=null &&
|
||||
content.getCharacterEncoding()==null &&
|
||||
__explicitCharset.contains(_encodingFrom))
|
||||
{
|
||||
setContentType(content.getMimeType().getBaseType().asString());
|
||||
}
|
||||
else
|
||||
{
|
||||
_fields.put(ct);
|
||||
_contentType=ct.getValue();
|
||||
_characterEncoding=content.getCharacterEncoding();
|
||||
_mimeType=content.getMimeType();
|
||||
}
|
||||
}
|
||||
|
||||
HttpField ce=content.getContentEncoding();
|
||||
if (ce!=null)
|
||||
|
|
|
@ -71,7 +71,7 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
|||
* that these callbacks may do some non-blocking IO work, but will always dispatch to the
|
||||
* {@link Executor} service any blocking, long running or application tasks.
|
||||
* <p>
|
||||
* The default number of selectors is equal to the number of processors available to the JVM,
|
||||
* The default number of selectors is equal to half of the number of processors available to the JVM,
|
||||
* which should allow optimal performance even if all the connections used are performing
|
||||
* significant non-blocking work in the callback tasks.
|
||||
*/
|
||||
|
|
|
@ -206,7 +206,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
private final CopyOnWriteArrayList<AliasCheck> _aliasChecks = new CopyOnWriteArrayList<ContextHandler.AliasCheck>();
|
||||
|
||||
public enum Availability { UNAVAILABLE,STARTING,AVAILABLE,SHUTDOWN,};
|
||||
private volatile Availability _availability;
|
||||
private volatile Availability _availability = Availability.UNAVAILABLE;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ContextHandler()
|
||||
|
@ -684,18 +684,12 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return true if this context is accepting new requests
|
||||
* @return true if this context is shutting down
|
||||
*/
|
||||
@ManagedAttribute("true for graceful shutdown, which allows existing requests to complete")
|
||||
public boolean isShutdown()
|
||||
{
|
||||
switch(_availability)
|
||||
{
|
||||
case SHUTDOWN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return _availability == Availability.SHUTDOWN;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -59,31 +59,25 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
*/
|
||||
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=16;
|
||||
private static final Logger LOG = Log.getLogger(GzipHandler.class);
|
||||
|
||||
public final static String GZIP = "gzip";
|
||||
public final static String DEFLATE = "deflate";
|
||||
public final static int DEFAULT_MIN_GZIP_SIZE=16;
|
||||
private int _minGzipSize=DEFAULT_MIN_GZIP_SIZE;
|
||||
private int _compressionLevel=Deflater.DEFAULT_COMPRESSION;
|
||||
private boolean _checkGzExists = true;
|
||||
private boolean _syncFlush = false;
|
||||
private int _inflateBufferSize = -1;
|
||||
private EnumSet<DispatcherType> _dispatchers = EnumSet.of(DispatcherType.REQUEST);
|
||||
|
||||
// non-static, as other GzipHandler instances may have different configurations
|
||||
private final ThreadLocal<Deflater> _deflater = new ThreadLocal<>();
|
||||
|
||||
private final IncludeExclude<String> _agentPatterns=new IncludeExclude<>(RegexSet.class);
|
||||
private final IncludeExclude<String> _methods = new IncludeExclude<>();
|
||||
private final IncludeExclude<String> _paths = new IncludeExclude<>(PathSpecSet.class);
|
||||
private final IncludeExclude<String> _mimeTypes = new IncludeExclude<>();
|
||||
|
||||
private HttpField _vary;
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Instantiates a new gzip handler.
|
||||
* The excluded Mime Types are initialized to common known
|
||||
|
@ -110,12 +104,13 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_mimeTypes.exclude("application/brotli");
|
||||
_mimeTypes.exclude("application/x-xz");
|
||||
_mimeTypes.exclude("application/x-rar-compressed");
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{} mime types {}",this,_mimeTypes);
|
||||
|
||||
_agentPatterns.exclude(".*MSIE 6.0.*");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param patterns Regular expressions matching user agents to exclude
|
||||
*/
|
||||
|
@ -124,7 +119,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_agentPatterns.exclude(patterns);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param methods The methods to exclude in compression
|
||||
*/
|
||||
|
@ -134,28 +128,24 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_methods.exclude(m);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public EnumSet<DispatcherType> getDispatcherTypes()
|
||||
{
|
||||
return _dispatchers;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setDispatcherTypes(EnumSet<DispatcherType> dispatchers)
|
||||
{
|
||||
_dispatchers = dispatchers;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setDispatcherTypes(DispatcherType... dispatchers)
|
||||
{
|
||||
_dispatchers = EnumSet.copyOf(Arrays.asList(dispatchers));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the mime types.
|
||||
* Adds mime types to the excluded list.
|
||||
*
|
||||
* @param types The mime types to exclude (without charset or other parameters).
|
||||
* For backward compatibility the mimetypes may be comma separated strings, but this
|
||||
* will not be supported in future versions.
|
||||
|
@ -166,9 +156,8 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_mimeTypes.exclude(StringUtil.csvSplit(t));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Add path to excluded paths list.
|
||||
* Add paths to excluded paths list.
|
||||
* <p>
|
||||
* There are 2 syntaxes supported, Servlet <code>url-pattern</code> based, and
|
||||
* Regex based. This means that the initial characters on the path spec
|
||||
|
@ -198,16 +187,14 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_paths.exclude(StringUtil.csvSplit(p));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param patterns Regular expressions matching user agents to exclude
|
||||
* @param patterns Regular expressions matching user agents to include
|
||||
*/
|
||||
public void addIncludedAgentPatterns(String... patterns)
|
||||
{
|
||||
_agentPatterns.include(patterns);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param methods The methods to include in compression
|
||||
*/
|
||||
|
@ -217,7 +204,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_methods.include(m);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return True if {@link Deflater#SYNC_FLUSH} is used, else {@link Deflater#NO_FLUSH}
|
||||
*/
|
||||
|
@ -226,7 +212,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
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
|
||||
|
@ -238,7 +223,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_syncFlush = syncFlush;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Add included mime types. Inclusion takes precedence over
|
||||
* exclusion.
|
||||
|
@ -252,9 +236,8 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_mimeTypes.include(StringUtil.csvSplit(t));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Add path specs to include.
|
||||
* Adds paths specs to the included list.
|
||||
* <p>
|
||||
* There are 2 syntaxes supported, Servlet <code>url-pattern</code> based, and
|
||||
* Regex based. This means that the initial characters on the path spec
|
||||
|
@ -270,7 +253,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
* <li>All other syntaxes are unsupported</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Note: inclusion takes precedence over exclude.
|
||||
* Note: inclusion takes precedence over exclusion.
|
||||
*
|
||||
* @param pathspecs Path specs (as per servlet spec) to include. If a
|
||||
* ServletContext is available, the paths are relative to the context path,
|
||||
|
@ -282,7 +265,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_paths.include(StringUtil.csvSplit(p));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
|
@ -290,19 +272,16 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
super.doStart();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean getCheckGzExists()
|
||||
{
|
||||
return _checkGzExists;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public int getCompressionLevel()
|
||||
{
|
||||
return _compressionLevel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Deflater getDeflater(Request request, long content_length)
|
||||
{
|
||||
|
@ -344,87 +323,73 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
return df;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getExcludedAgentPatterns()
|
||||
{
|
||||
Set<String> excluded=_agentPatterns.getExcluded();
|
||||
return excluded.toArray(new String[excluded.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getExcludedMethods()
|
||||
{
|
||||
Set<String> excluded=_methods.getExcluded();
|
||||
return excluded.toArray(new String[excluded.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getExcludedMimeTypes()
|
||||
{
|
||||
Set<String> excluded=_mimeTypes.getExcluded();
|
||||
return excluded.toArray(new String[excluded.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getExcludedPaths()
|
||||
{
|
||||
Set<String> excluded=_paths.getExcluded();
|
||||
return excluded.toArray(new String[excluded.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getIncludedAgentPatterns()
|
||||
{
|
||||
Set<String> includes=_agentPatterns.getIncluded();
|
||||
return includes.toArray(new String[includes.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getIncludedMethods()
|
||||
{
|
||||
Set<String> includes=_methods.getIncluded();
|
||||
return includes.toArray(new String[includes.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getIncludedMimeTypes()
|
||||
{
|
||||
Set<String> includes=_mimeTypes.getIncluded();
|
||||
return includes.toArray(new String[includes.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getIncludedPaths()
|
||||
{
|
||||
Set<String> includes=_paths.getIncluded();
|
||||
return includes.toArray(new String[includes.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public String[] getMethods()
|
||||
{
|
||||
return getIncludedMethods();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Get the minimum response size.
|
||||
*
|
||||
* @return minimum response size
|
||||
* @return minimum response size that triggers compression
|
||||
*/
|
||||
public int getMinGzipSize()
|
||||
{
|
||||
return _minGzipSize;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected HttpField getVaryField()
|
||||
{
|
||||
return _vary;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return size in bytes of the buffer to inflate compressed request, or 0 for no inflation.
|
||||
*/
|
||||
|
@ -433,7 +398,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
return _inflateBufferSize;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param size size in bytes of the buffer to inflate compressed request, or 0 for no inflation.
|
||||
*/
|
||||
|
@ -442,10 +406,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_inflateBufferSize = size;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
|
@ -568,12 +528,9 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Checks to see if the userAgent is excluded
|
||||
*
|
||||
* @param ua the user agent
|
||||
* @return boolean true if excluded
|
||||
* @return whether compressing is allowed for the given user agent
|
||||
*/
|
||||
protected boolean isAgentGzipable(String ua)
|
||||
{
|
||||
|
@ -583,20 +540,15 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
return _agentPatterns.test(ua);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean isMimeTypeGzipable(String mimetype)
|
||||
{
|
||||
return _mimeTypes.test(mimetype);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Checks to see if the path is included or not excluded
|
||||
*
|
||||
* @param requestURI
|
||||
* the request uri
|
||||
* @return boolean true if gzipable
|
||||
* @param requestURI the request uri
|
||||
* @return whether compressing is allowed for the given the path
|
||||
*/
|
||||
protected boolean isPathGzipable(String requestURI)
|
||||
{
|
||||
|
@ -606,7 +558,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
return _paths.test(requestURI);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void recycle(Deflater deflater)
|
||||
{
|
||||
|
@ -615,9 +566,8 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_deflater.set(deflater);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param checkGzExists If true, check if a static gz file exists for
|
||||
* @param checkGzExists whether to check if a static gz file exists for
|
||||
* the resource that the DefaultServlet may serve as precompressed.
|
||||
*/
|
||||
public void setCheckGzExists(boolean checkGzExists)
|
||||
|
@ -625,7 +575,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_checkGzExists = checkGzExists;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param compressionLevel The compression level to use to initialize {@link Deflater#setLevel(int)}
|
||||
*/
|
||||
|
@ -634,7 +583,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_compressionLevel = compressionLevel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param patterns Regular expressions matching user agents to exclude
|
||||
*/
|
||||
|
@ -644,19 +592,16 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
addExcludedAgentPatterns(patterns);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param method to exclude
|
||||
* @param methods the HTTP methods to exclude
|
||||
*/
|
||||
public void setExcludedMethods(String... method)
|
||||
public void setExcludedMethods(String... methods)
|
||||
{
|
||||
_methods.getExcluded().clear();
|
||||
_methods.exclude(method);
|
||||
_methods.exclude(methods);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the mime types.
|
||||
* @param types The mime types to exclude (without charset or other parameters)
|
||||
*/
|
||||
public void setExcludedMimeTypes(String... types)
|
||||
|
@ -665,7 +610,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_mimeTypes.exclude(types);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param pathspecs Path specs (as per servlet spec) to exclude. If a
|
||||
* ServletContext is available, the paths are relative to the context path,
|
||||
|
@ -677,7 +621,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_paths.exclude(pathspecs);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param patterns Regular expressions matching user agents to include
|
||||
*/
|
||||
|
@ -687,7 +630,6 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
addIncludedAgentPatterns(patterns);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param methods The methods to include in compression
|
||||
*/
|
||||
|
@ -697,10 +639,9 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_methods.include(methods);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set included mime types. Inclusion takes precedence over
|
||||
* exclusion.
|
||||
* Sets included mime types. Inclusion takes precedence over exclusion.
|
||||
*
|
||||
* @param types The mime types to include (without charset or other parameters)
|
||||
*/
|
||||
public void setIncludedMimeTypes(String... types)
|
||||
|
@ -709,9 +650,9 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_mimeTypes.include(types);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the path specs to include. Inclusion takes precedence over exclusion.
|
||||
*
|
||||
* @param pathspecs Path specs (as per servlet spec) to include. If a
|
||||
* ServletContext is available, the paths are relative to the context path,
|
||||
* otherwise they are absolute
|
||||
|
@ -722,9 +663,8 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
_paths.include(pathspecs);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the minimum response size to trigger dynamic compresssion
|
||||
* Set the minimum response size to trigger dynamic compression
|
||||
*
|
||||
* @param minGzipSize minimum response size in bytes
|
||||
*/
|
||||
|
@ -732,4 +672,24 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
|||
{
|
||||
_minGzipSize = minGzipSize;
|
||||
}
|
||||
|
||||
public void setIncludedMethodList(String csvMethods)
|
||||
{
|
||||
setIncludedMethods(StringUtil.csvSplit(csvMethods));
|
||||
}
|
||||
|
||||
public String getIncludedMethodList()
|
||||
{
|
||||
return String.join(",", getIncludedMethods());
|
||||
}
|
||||
|
||||
public void setExcludedMethodList(String csvMethods)
|
||||
{
|
||||
setExcludedMethods(StringUtil.csvSplit(csvMethods));
|
||||
}
|
||||
|
||||
public String getExcludedMethodList()
|
||||
{
|
||||
return String.join(",", getExcludedMethods());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -447,7 +447,11 @@ public class ContextHandlerTest
|
|||
Assert.assertTrue(handler.isProtectedTarget("/ABC/7777"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIsShutdown() {
|
||||
ContextHandler handler = new ContextHandler();
|
||||
Assert.assertEquals(false, handler.isShutdown());
|
||||
}
|
||||
|
||||
private void checkResourcePathsForExampleWebApp(String root) throws IOException
|
||||
{
|
||||
|
|
|
@ -729,6 +729,8 @@ public class DefaultServletTest
|
|||
String response = connector.getResponse("GET /context/data0.txt HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("Content-Length: 12", response);
|
||||
assertResponseNotContains("Extra Info", response);
|
||||
assertResponseContains("Content-Type: text/plain", response);
|
||||
assertResponseNotContains("Content-Type: text/plain;charset=utf-8", response);
|
||||
|
||||
server.stop();
|
||||
context.addFilter(OutputFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
|
||||
|
@ -738,6 +740,7 @@ public class DefaultServletTest
|
|||
assertResponseContains("Content-Length: 2", response); // 20 something long
|
||||
assertResponseContains("Extra Info", response);
|
||||
assertResponseNotContains("Content-Length: 12", response);
|
||||
assertResponseContains("Content-Type: text/plain;charset=utf-8", response);
|
||||
|
||||
server.stop();
|
||||
context.getServletHandler().setFilterMappings(new FilterMapping[]{});
|
||||
|
@ -1226,6 +1229,7 @@ public class DefaultServletTest
|
|||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
|
||||
{
|
||||
response.getOutputStream().println("Extra Info");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ public class GCloudSessionTestSupport
|
|||
|
||||
public GCloudSessionTestSupport ()
|
||||
{
|
||||
DatastoreOptions options = _helper.options();
|
||||
_ds = options.service();
|
||||
DatastoreOptions options = _helper.getOptions();
|
||||
_ds = options.getService();
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class GCloudSessionTestSupport
|
|||
public Set<String> getSessionIds () throws Exception
|
||||
{
|
||||
HashSet<String> ids = new HashSet<String>();
|
||||
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.EntityDataModel.KIND);
|
||||
GqlQuery.Builder builder = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.EntityDataModel.KIND);
|
||||
|
||||
Query<Entity> query = builder.build();
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class GCloudSessionTestSupport
|
|||
public void listSessions () throws Exception
|
||||
{
|
||||
|
||||
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.EntityDataModel.KIND);
|
||||
GqlQuery.Builder builder = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.EntityDataModel.KIND);
|
||||
|
||||
Query<Entity> query = builder.build();
|
||||
|
||||
|
@ -151,7 +151,7 @@ public class GCloudSessionTestSupport
|
|||
|
||||
public void assertSessions(int count) throws Exception
|
||||
{
|
||||
Query<Key> query = Query.keyQueryBuilder().kind(GCloudSessionDataStore.EntityDataModel.KIND).build();
|
||||
Query<Key> query = Query.newKeyQueryBuilder().setKind(GCloudSessionDataStore.EntityDataModel.KIND).build();
|
||||
QueryResults<Key> results = _ds.run(query);
|
||||
assertNotNull(results);
|
||||
int actual = 0;
|
||||
|
@ -165,7 +165,7 @@ public class GCloudSessionTestSupport
|
|||
|
||||
public void deleteSessions () throws Exception
|
||||
{
|
||||
Query<Key> query = Query.keyQueryBuilder().kind(GCloudSessionDataStore.EntityDataModel.KIND).build();
|
||||
Query<Key> query = Query.newKeyQueryBuilder().setKind(GCloudSessionDataStore.EntityDataModel.KIND).build();
|
||||
QueryResults<Key> results = _ds.run(query);
|
||||
|
||||
if (results != null)
|
||||
|
|
Loading…
Reference in New Issue