Merge pull request #3631 from garydgregory/jetty-9.4.x_proxy_with_custom_status_code_redux
Allow subclasses to map exceptions to status codes.
This commit is contained in:
commit
8cdb36f32b
|
@ -568,13 +568,18 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
|||
boolean aborted = proxyRequest.abort(failure);
|
||||
if (!aborted)
|
||||
{
|
||||
int status = failure instanceof TimeoutException ?
|
||||
HttpStatus.REQUEST_TIMEOUT_408 :
|
||||
HttpStatus.INTERNAL_SERVER_ERROR_500;
|
||||
int status = clientRequestStatus(failure);
|
||||
sendProxyResponseError(clientRequest, proxyResponse, status);
|
||||
}
|
||||
}
|
||||
|
||||
protected int clientRequestStatus(Throwable failure)
|
||||
{
|
||||
return failure instanceof TimeoutException ?
|
||||
HttpStatus.REQUEST_TIMEOUT_408 :
|
||||
HttpStatus.INTERNAL_SERVER_ERROR_500;
|
||||
}
|
||||
|
||||
protected void onServerResponseHeaders(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse)
|
||||
{
|
||||
for (HttpField field : serverResponse.getHeaders())
|
||||
|
@ -639,9 +644,7 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
|||
if (_log.isDebugEnabled())
|
||||
_log.debug(getRequestId(clientRequest) + " proxying failed", failure);
|
||||
|
||||
int status = failure instanceof TimeoutException ?
|
||||
HttpStatus.GATEWAY_TIMEOUT_504 :
|
||||
HttpStatus.BAD_GATEWAY_502;
|
||||
int status = proxyResponseStatus(failure);
|
||||
int serverStatus = serverResponse == null ? status : serverResponse.getStatus();
|
||||
if (expects100Continue(clientRequest) && serverStatus >= HttpStatus.OK_200)
|
||||
status = serverStatus;
|
||||
|
@ -649,6 +652,13 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
|||
|
||||
}
|
||||
|
||||
protected int proxyResponseStatus(Throwable failure)
|
||||
{
|
||||
return failure instanceof TimeoutException ?
|
||||
HttpStatus.GATEWAY_TIMEOUT_504 :
|
||||
HttpStatus.BAD_GATEWAY_502;
|
||||
}
|
||||
|
||||
protected int getRequestId(HttpServletRequest clientRequest)
|
||||
{
|
||||
return System.identityHashCode(clientRequest);
|
||||
|
|
Loading…
Reference in New Issue