From efdf3c2473eb191d19169bd30742e22ece6365c0 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sat, 20 Oct 2018 10:15:05 +1100 Subject: [PATCH] Issue #2970 ensure onComplete is called (#2971) * Issue #2970 ensure onComplete is called * Cleanup after review - single try Signed-off-by: Greg Wilkins --- .../org/eclipse/jetty/server/HttpChannel.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 8b490299d21..43ab02dc183 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -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; }