Merge remote-tracking branch 'origin/jetty-12.0.x' into jetty-12.1.x

This commit is contained in:
gregw 2024-08-30 08:42:37 +10:00
commit f588c53e41
2 changed files with 33 additions and 4 deletions

View File

@ -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);
}
@ -620,7 +623,7 @@ public abstract class HttpSender
protected void onFailure(Throwable x)
{
failRequest(x);
internalAbort(exchange, x);
internalAbort(x);
Promise<Boolean> promise = abort;
if (promise != null)

View File

@ -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<String> ATTRIBUTES = Set.of(ERROR_MESSAGE, ERROR_EXCEPTION, ERROR_STATUS);