Issue #2970 ensure onComplete is called (#2971)

* Issue #2970 ensure onComplete is called
* Cleanup after review - single try

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2018-10-20 10:15:05 +11:00 committed by GitHub
parent edc47818e2
commit efdf3c2473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 20 deletions

View File

@ -481,33 +481,38 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
case COMPLETE:
{
if (!_response.isCommitted() && !_request.isHandled())
try
{
_response.sendError(HttpStatus.NOT_FOUND_404);
}
else
{
// RFC 7230, section 3.3.
int status = _response.getStatus();
boolean hasContent = !(_request.isHead() ||
if (!_response.isCommitted() && !_request.isHandled())
{
_response.sendError(HttpStatus.NOT_FOUND_404);
}
else
{
// RFC 7230, section 3.3.
int status = _response.getStatus();
boolean hasContent = !(_request.isHead() ||
HttpMethod.CONNECT.is(_request.getMethod()) && status == HttpStatus.OK_200 ||
HttpStatus.isInformational(status) ||
status == HttpStatus.NO_CONTENT_204 ||
status == HttpStatus.NOT_MODIFIED_304);
if (hasContent && !_response.isContentComplete(_response.getHttpOutput().getWritten()))
{
if (isCommitted())
abort(new IOException("insufficient content written"));
else
_response.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500,"insufficient content written");
if (hasContent && !_response.isContentComplete(_response.getHttpOutput().getWritten()))
{
if (isCommitted())
abort(new IOException("insufficient content written"));
else
_response.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500, "insufficient content written");
}
}
_response.closeOutput();
}
finally
{
_request.setHandled(true);
_state.onComplete();
onCompleted();
}
_response.closeOutput();
_request.setHandled(true);
_state.onComplete();
onCompleted();
break loop;
}