Merged branch 'jetty-9.3.x' into 'master'.

This commit is contained in:
Simone Bordet 2015-11-05 15:53:15 +01:00
commit d8a52315c7
3 changed files with 18 additions and 12 deletions

View File

@ -413,11 +413,11 @@ public abstract class AbstractProxyServlet extends HttpServlet
* like {@link HttpServletResponse#sendError(int)}.</p>
*
* @param clientRequest the client request
* @param clientResponse the client response
* @param proxyResponse the client response
*/
protected void onProxyRewriteFailed(HttpServletRequest clientRequest, HttpServletResponse clientResponse)
protected void onProxyRewriteFailed(HttpServletRequest clientRequest, HttpServletResponse proxyResponse)
{
clientResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
sendProxyResponseError(clientRequest, proxyResponse, HttpStatus.FORBIDDEN_403);
}
protected boolean hasContent(HttpServletRequest clientRequest)
@ -549,8 +549,7 @@ public abstract class AbstractProxyServlet extends HttpServlet
int status = failure instanceof TimeoutException ?
HttpStatus.REQUEST_TIMEOUT_408 :
HttpStatus.INTERNAL_SERVER_ERROR_500;
proxyResponse.setStatus(status);
clientRequest.getAsyncContext().complete();
sendProxyResponseError(clientRequest, proxyResponse, status);
}
}
@ -636,13 +635,10 @@ public abstract class AbstractProxyServlet extends HttpServlet
else
{
proxyResponse.resetBuffer();
if (failure instanceof TimeoutException)
proxyResponse.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
else
proxyResponse.setStatus(HttpServletResponse.SC_BAD_GATEWAY);
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
AsyncContext asyncContext = clientRequest.getAsyncContext();
asyncContext.complete();
int status = failure instanceof TimeoutException ?
HttpStatus.GATEWAY_TIMEOUT_504 :
HttpStatus.BAD_GATEWAY_502;
sendProxyResponseError(clientRequest, proxyResponse, status);
}
}
@ -651,6 +647,14 @@ public abstract class AbstractProxyServlet extends HttpServlet
return System.identityHashCode(clientRequest);
}
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();
}
/**
* <p>Utility class that implement transparent proxy functionalities.</p>
* <p>Configuration parameters:</p>

View File

@ -138,6 +138,7 @@ public class AsyncMiddleManServlet extends AbstractProxyServlet
return new ProxyWriter(clientRequest, proxyResponse);
}
@Override
protected Response.CompleteListener newProxyResponseListener(HttpServletRequest clientRequest, HttpServletResponse proxyResponse)
{
return new ProxyResponseListener(clientRequest, proxyResponse);

View File

@ -93,6 +93,7 @@ public class ProxyServlet extends AbstractProxyServlet
return new ProxyInputStreamContentProvider(request, response, proxyRequest, request.getInputStream());
}
@Override
protected Response.Listener newProxyResponseListener(HttpServletRequest request, HttpServletResponse response)
{
return new ProxyResponseListener(request, response);