476641 - Proxy rewriteTarget() null return does not call error handler.
Introduced sendProxyResponseError(), centralizing the place where an error is returned to the client, so that applications may override the behavior.
This commit is contained in:
parent
4cf308a7db
commit
e0963543d2
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue