diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java index a85b332f64f0..0d6c654fb8a2 100644 --- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java +++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpChannel.java @@ -56,7 +56,6 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.ExceptionUtil; import org.eclipse.jetty.util.HostPort; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.SharedBlockingCallback.Blocker; @@ -561,16 +560,7 @@ public boolean handle() { if (LOG.isDebugEnabled()) LOG.debug("Could not perform ERROR dispatch, aborting", x); - try - { - _response.resetContent(); - sendResponseAndComplete(); - } - catch (Throwable t) - { - ExceptionUtil.addSuppressedIfNotAssociated(x, t); - throw x; - } + abort(x); } finally { diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpOutput.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpOutput.java index e4849605b04a..538b302f1b87 100644 --- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpOutput.java +++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/HttpOutput.java @@ -241,6 +241,15 @@ public long getWritten() return _written; } + /** + * Used by ServletCoreResponse when it bypasses HttpOutput to update bytes written. + * @param written The bytes written + */ + void setBytesWritten(int written) + { + _written = written; + } + public void reopen() { try (AutoLock l = _channelState.lock()) diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ServletCoreResponse.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ServletCoreResponse.java index 0f02b0757f32..845deb5aa3c1 100644 --- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ServletCoreResponse.java +++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ServletCoreResponse.java @@ -137,12 +137,15 @@ public void write(boolean last, ByteBuffer byteBuffer, Callback callback) last = false; try { - if (!_wrapped && !_baseResponse.isWritingOrStreaming()) + if (last && !_wrapped && !_baseResponse.isWritingOrStreaming()) { + // We can bypass the HttpOutput stream, but we need to update its bytes written + _baseResponse.getHttpOutput().setBytesWritten(byteBuffer.remaining()); _coreResponse.write(last, byteBuffer, callback); } else { + // Write the byteBuffer via the HttpOutput stream or writer wrapping the stream if (BufferUtil.hasContent(byteBuffer)) { if (isWriting()) @@ -333,7 +336,10 @@ public Mutable add(HttpHeader header, String value) @Override public Mutable add(HttpField field) { - _response.addHeader(field.getName(), field.getValue()); + if (field.getHeader() == HttpHeader.CONTENT_LENGTH) + _response.setContentLengthLong(field.getLongValue()); + else + _response.addHeader(field.getName(), field.getValue()); return this; }