From ed1cadc449bfd711e7fb5d4d409e4eb57be9321b Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Wed, 28 Aug 2024 19:43:54 +0200 Subject: [PATCH 1/2] fix npe when onCompleteFailure happens after reset (#12199) Fix npe when onCompleteFailure happens after reset Signed-off-by: Ludovic Orban --- .../org/eclipse/jetty/client/transport/HttpSender.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java index 55476b7f48c..69bade58dd6 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java @@ -386,8 +386,11 @@ public abstract class HttpSender } } - private void internalAbort(HttpExchange exchange, Throwable failure) + private void internalAbort(Throwable failure) { + HttpExchange exchange = getHttpExchange(); + if (exchange == null) + return; anyToFailure(failure); abortRequest(exchange); } @@ -626,7 +629,7 @@ public abstract class HttpSender } failRequest(x); - internalAbort(exchange, x); + internalAbort(x); Promise promise = abort; if (promise != null) From 4755fa3f6816dfe365744c7fe9b4035d0bb15990 Mon Sep 17 00:00:00 2001 From: Dmitry Kaukov Date: Fri, 30 Aug 2024 08:33:10 +1000 Subject: [PATCH 2/2] Customizable error page buffer size (#11654) Customizable error page buffer size --------- Co-authored-by: Greg Wilkins --- .../jetty/server/handler/ErrorHandler.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java index d32e4255c39..bb2ea6b6a93 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java @@ -75,6 +75,7 @@ public class ErrorHandler implements Request.Handler boolean _showStacks = false; boolean _showCauses = false; boolean _showMessageInTitle = true; + int _bufferSize = -1; String _defaultResponseMimeType = Type.TEXT_HTML.asString(); HttpField _cacheControl = new PreEncodedHttpField(HttpHeader.CACHE_CONTROL, "must-revalidate,no-cache,no-store"); @@ -198,8 +199,7 @@ public class ErrorHandler implements Request.Handler return false; } - int bufferSize = request.getConnectionMetaData().getHttpConfiguration().getOutputBufferSize(); - bufferSize = Math.min(8192, bufferSize); // TODO ? + int bufferSize = getBufferSize() <= 0 ? computeBufferSize(request) : getBufferSize(); ByteBufferPool byteBufferPool = request.getComponents().getByteBufferPool(); RetainableByteBuffer buffer = byteBufferPool.acquire(bufferSize, false); @@ -266,6 +266,13 @@ public class ErrorHandler implements Request.Handler } } + protected int computeBufferSize(Request request) + { + int bufferSize = request.getConnectionMetaData().getHttpConfiguration().getOutputBufferSize(); + bufferSize = Math.min(8192, bufferSize); + return bufferSize; + } + protected void writeErrorHtml(Request request, Writer writer, Charset charset, int code, String message, Throwable cause, boolean showStacks) throws IOException { if (message == null) @@ -530,6 +537,25 @@ public class ErrorHandler implements Request.Handler return errorHandler; } + /** + * @return Buffer size for entire error response. If error page is bigger than buffer size, it will be truncated. + * With a -1 meaning that a heuristic will be used (e.g. min(8K, httpConfig.bufferSize)) + */ + @ManagedAttribute("Buffer size for entire error response") + public int getBufferSize() + { + return _bufferSize; + } + + /** + * @param bufferSize Buffer size for entire error response. If error page is bigger than buffer size, it will be truncated. + * With a -1 meaning that a heuristic will be used (e.g. min(8K, httpConfig.bufferSize)) + */ + public void setBufferSize(int bufferSize) + { + this._bufferSize = bufferSize; + } + public static class ErrorRequest extends Request.AttributesWrapper { private static final Set ATTRIBUTES = Set.of(ERROR_MESSAGE, ERROR_EXCEPTION, ERROR_STATUS);