Skip to content

Commit

Permalink
Merge branch 'jetty-9.4.x' into jetty-9.4.x-ewyk
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed Mar 30, 2017
2 parents f89b08d + a8ff18d commit 69003d3
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 156 deletions.
2 changes: 1 addition & 1 deletion jetty-gcloud/pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -153,7 +153,7 @@ public enum Code
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"),
Expand Down
Expand Up @@ -31,6 +31,14 @@ public void testInvalidGetCode()
assertNull("Invalid code: 800", HttpStatus.getCode(800));
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()
{
Expand Down
82 changes: 40 additions & 42 deletions jetty-server/src/main/config/etc/jetty-gzip.xml
Expand Up @@ -12,54 +12,52 @@
<Call name="insertHandler">
<Arg>
<New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
<Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set>
<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="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set>
<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">
<Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
</Array>
</Set>
<Set name="excludedAgentPatterns">
<Array type="String">
<Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
</Array>
</Set>

<Set name="includedMethods">
<Array type="String">
<Item>GET</Item>
</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="includedPaths">
<Array type="String">
<Item>/*</Item>
</Array>
</Set>
-->
<!--
<Set name="includedMethods">
<Array type="String">
<Item>GET</Item>
</Array>
</Set>
<!--
<Set name="excludedPaths">
<Array type="String">
<Item>*.gz</Item>
</Array>
</Set>
-->
<Set name="includedPaths">
<Array type="String">
<Item>/*</Item>
</Array>
</Set>
<!--
<Call name="addIncludedMimeTypes">
<Arg><Array type="String">
<Item>some/type</Item>
</Array></Arg>
</Call>
-->
<Set name="excludedPaths">
<Array type="String">
<Item>*.gz</Item>
</Array>
</Set>
<!--
<Call name="addExcludedMimeTypes">
<Arg><Array type="String">
<Item>some/type</Item>
</Array></Arg>
</Call>
-->
<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>
</Array></Arg>
</Call>
-->

</New>
</Arg>
Expand Down
6 changes: 6 additions & 0 deletions jetty-server/src/main/config/modules/gzip.mod
Expand Up @@ -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=
Expand Up @@ -129,7 +129,7 @@
* <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.)
*/
Expand Down
Expand Up @@ -225,28 +225,53 @@ public String toString()
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)
{
response.getOutputStream().close();
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)
{
response.getWriter().close();
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;
}
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
Expand Up @@ -119,6 +119,7 @@ public enum OutputType

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)
Expand Down Expand Up @@ -1425,10 +1426,19 @@ else if (contentLength>0)
HttpField ct=content.getContentType();
if (ct!=null)
{
_fields.put(ct);
_contentType=ct.getValue();
_characterEncoding=content.getCharacterEncoding();
_mimeType=content.getMimeType();
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();
Expand Down
Expand Up @@ -71,7 +71,7 @@
* 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.
*/
Expand Down
Expand Up @@ -206,7 +206,7 @@ public static void setServerInfo(String serverInfo)
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()
Expand Down Expand Up @@ -684,18 +684,12 @@ protected boolean isProgrammaticListener(EventListener listener)

/* ------------------------------------------------------------ */
/**
* @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;
}

/* ------------------------------------------------------------ */
Expand Down

0 comments on commit 69003d3

Please sign in to comment.