Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x

This commit is contained in:
Greg Wilkins 2017-07-13 15:41:54 +02:00
commit 8ca8735c95
4 changed files with 44 additions and 38 deletions

View File

@ -638,35 +638,14 @@ public abstract class AbstractProxyServlet extends HttpServlet
if (_log.isDebugEnabled())
_log.debug(getRequestId(clientRequest) + " proxying failed", failure);
if (proxyResponse.isCommitted())
{
try
{
// Use Jetty specific behavior to close connection.
proxyResponse.sendError(-1);
if (clientRequest.isAsyncStarted())
{
AsyncContext asyncContext = clientRequest.getAsyncContext();
asyncContext.complete();
}
}
catch (Throwable x)
{
if (_log.isDebugEnabled())
_log.debug(getRequestId(clientRequest) + " could not close the connection", failure);
}
}
else
{
proxyResponse.resetBuffer();
int status = failure instanceof TimeoutException ?
HttpStatus.GATEWAY_TIMEOUT_504 :
HttpStatus.BAD_GATEWAY_502;
int serverStatus = serverResponse == null ? status : serverResponse.getStatus();
if (expects100Continue(clientRequest) && serverStatus >= HttpStatus.OK_200)
status = serverStatus;
sendProxyResponseError(clientRequest, proxyResponse, status);
}
int status = failure instanceof TimeoutException ?
HttpStatus.GATEWAY_TIMEOUT_504 :
HttpStatus.BAD_GATEWAY_502;
int serverStatus = serverResponse == null ? status : serverResponse.getStatus();
if (expects100Continue(clientRequest) && serverStatus >= HttpStatus.OK_200)
status = serverStatus;
sendProxyResponseError(clientRequest, proxyResponse, status);
}
protected int getRequestId(HttpServletRequest clientRequest)
@ -676,10 +655,24 @@ public abstract class AbstractProxyServlet extends HttpServlet
protected void sendProxyResponseError(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, int status)
{
proxyResponse.setStatus(status);
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
if (clientRequest.isAsyncStarted())
clientRequest.getAsyncContext().complete();
try
{
if (!proxyResponse.isCommitted())
{
proxyResponse.resetBuffer();
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
}
proxyResponse.sendError(status);
}
catch(Exception e)
{
_log.ignore(e);
}
finally
{
if (clientRequest.isAsyncStarted())
clientRequest.getAsyncContext().complete();
}
}
protected void onContinue(HttpServletRequest clientRequest, Request proxyRequest)

View File

@ -1087,10 +1087,10 @@ public class ProxyServletTest
Response response = listener.get(5, TimeUnit.SECONDS);
Assert.assertEquals(504, response.getStatus());
// Make sure there is no content, as the proxy-to-client response has been reset.
// Make sure there is error page content, as the proxy-to-client response has been reset.
InputStream input = listener.getInputStream();
Assert.assertEquals(-1, input.read());
String body = IO.toString(input);
Assert.assertThat(body,Matchers.containsString("HTTP ERROR: 504"));
chunk1Latch.countDown();
// Result succeeds because a 504 is a valid HTTP response.

View File

@ -246,11 +246,11 @@ public class InetAddressSet extends AbstractSet<String> implements Set<String>,
_octets = cidr/8;
_mask = 0xff&(0xff<<(8-cidr%8));
_masked = _mask==0?0:_raw[_octets]&_mask;
if (cidr>(_raw.length*8))
throw new IllegalArgumentException("CIDR too large: "+pattern);
if (_mask!=0 && _raw[_octets]!=_masked)
if (_mask!=0 && (0xff&_raw[_octets])!=_masked)
throw new IllegalArgumentException("CIDR bits non zero: "+pattern);
for (int o=_octets+(_mask==0?0:1);o<_raw.length;o++)

View File

@ -134,8 +134,21 @@ public class InetAddressSetTest
set.add("0.0.0.0/0");
assertTrue(set.test(InetAddress.getByName("10.11.0.0")));
// test #1664
set.add("2.144.0.0/14");
set.add("2.176.0.0/12");
set.add("5.22.0.0/17");
set.add("5.22.192.0/19");
assertTrue(set.test(InetAddress.getByName("2.144.0.1")));
assertTrue(set.test(InetAddress.getByName("2.176.0.1")));
assertTrue(set.test(InetAddress.getByName("5.22.0.1")));
assertTrue(set.test(InetAddress.getByName("5.22.192.1")));
}
@Test
public void testBadCIDR() throws Exception
{