parent
070a58ff59
commit
8795781923
|
@ -626,27 +626,6 @@ 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;
|
||||
|
@ -654,7 +633,7 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
|||
if (expects100Continue(clientRequest) && serverStatus >= HttpStatus.OK_200)
|
||||
status = serverStatus;
|
||||
sendProxyResponseError(clientRequest, proxyResponse, status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected int getRequestId(HttpServletRequest clientRequest)
|
||||
|
@ -664,11 +643,28 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
|||
|
||||
protected void sendProxyResponseError(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, int status)
|
||||
{
|
||||
proxyResponse.setStatus(status);
|
||||
try
|
||||
{
|
||||
System.err.println("sendError "+status+" "+proxyResponse.isCommitted());
|
||||
new Throwable().printStackTrace();
|
||||
if (!proxyResponse.isCommitted())
|
||||
{
|
||||
proxyResponse.resetBuffer();
|
||||
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
|
||||
}
|
||||
proxyResponse.sendError(status);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
_log.ignore(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (clientRequest.isAsyncStarted())
|
||||
clientRequest.getAsyncContext().complete();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onContinue(HttpServletRequest clientRequest, Request proxyRequest)
|
||||
{
|
||||
|
|
|
@ -1074,10 +1074,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.
|
||||
|
|
Loading…
Reference in New Issue