Skip to content

Commit

Permalink
476641 - Proxy rewriteTarget() null return does not call error handler.
Browse files Browse the repository at this point in the history
Introduced sendProxyResponseError(), centralizing the place where an
error is returned to the client, so that applications may override the
behavior.
  • Loading branch information
sbordet committed Nov 5, 2015
1 parent 4cf308a commit e096354
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ protected String rewriteTarget(HttpServletRequest clientRequest)
* 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)
Expand Down Expand Up @@ -549,8 +549,7 @@ protected void onClientRequestFailure(HttpServletRequest clientRequest, Request
int status = failure instanceof TimeoutException ?
HttpStatus.REQUEST_TIMEOUT_408 :
HttpStatus.INTERNAL_SERVER_ERROR_500;
proxyResponse.setStatus(status);
clientRequest.getAsyncContext().complete();
sendProxyResponseError(clientRequest, proxyResponse, status);
}
}

Expand Down Expand Up @@ -636,13 +635,10 @@ protected void onProxyResponseFailure(HttpServletRequest clientRequest, HttpServ
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);
}
}

Expand All @@ -651,6 +647,14 @@ protected int getRequestId(HttpServletRequest clientRequest)
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>
Expand Down

0 comments on commit e096354

Please sign in to comment.