jetty-9 commitError always completes state

This commit is contained in:
Greg Wilkins 2012-05-18 09:48:15 +02:00
parent 74e0063f3c
commit b87e0f776b
2 changed files with 17 additions and 21 deletions

View File

@ -357,7 +357,7 @@ public abstract class HttpChannel
LOG.warn(String.valueOf(_uri),e); LOG.warn(String.valueOf(_uri),e);
async_exception=e; async_exception=e;
_request.setHandled(true); _request.setHandled(true);
sendError(500, null, e.toString(), true); commitError(500, null, e.toString());
} }
finally finally
{ {
@ -389,11 +389,10 @@ public abstract class HttpChannel
_response.addHeader(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE.toString()); _response.addHeader(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE.toString());
} }
if (!_response.isCommitted() && !_request.isHandled())
sendError(HttpServletResponse.SC_NOT_FOUND,null,null,false);
try try
{ {
if (!_response.isCommitted() && !_request.isHandled())
_response.sendError(404);
_response.complete(); _response.complete();
} }
catch(IOException e) catch(IOException e)
@ -409,16 +408,17 @@ public abstract class HttpChannel
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
protected boolean sendError(final int status, final String reason, String content, boolean close) protected boolean commitError(final int status, final String reason, String content)
{ {
LOG.debug("{} sendError {} {}",this,status,reason);
if (_response.isCommitted()) if (_response.isCommitted())
return false; return false;
try try
{ {
_response.setStatus(status,reason); _response.setStatus(status,reason);
if (close) _responseFields.add(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
_responseFields.add(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
ByteBuffer buffer=null; ByteBuffer buffer=null;
if (content!=null) if (content!=null)
@ -436,6 +436,12 @@ public abstract class HttpChannel
{ {
LOG.debug("failed to sendError {} {}",status, reason, e); LOG.debug("failed to sendError {} {}",status, reason, e);
} }
finally
{
if (_state.isIdle())
_state.complete();
_in.shutdownInput();
}
return false; return false;
} }
@ -613,21 +619,13 @@ public abstract class HttpChannel
if (!_host) if (!_host)
{ {
LOG.debug("!host {}",this); commitError(HttpStatus.BAD_REQUEST_400,"No Host Header",null);
_responseFields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE);
_in.shutdownInput();
sendError(HttpStatus.BAD_REQUEST_400,"No Host Header",null,true);
_state.complete();
return true; return true;
} }
if (_expect) if (_expect)
{ {
LOG.debug("!expectation {}",this); commitError(HttpStatus.EXPECTATION_FAILED_417,null,null);
_responseFields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE);
_in.shutdownInput();
sendError(HttpStatus.EXPECTATION_FAILED_417,null,null,true);
_state.complete();
return true; return true;
} }
@ -666,9 +664,7 @@ public abstract class HttpChannel
@Override @Override
public void badMessage(String reason) public void badMessage(String reason)
{ {
_in.shutdownInput(); commitError(HttpStatus.BAD_REQUEST_400,reason,null);
sendError(HttpStatus.BAD_REQUEST_400,reason,null,true);
_state.complete();
} }
@Override @Override

View File

@ -1056,7 +1056,7 @@ public class Request implements HttpServletRequest
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
if (_channel != null) if (_channel != null)
_channel.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true); _channel.commitError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null);
} }
return _serverName; return _serverName;
} }