Customizable error page buffer size (#11654)

Customizable error page buffer size

---------

Co-authored-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Dmitry Kaukov 2024-08-30 08:33:10 +10:00 committed by GitHub
parent ed1cadc449
commit 4755fa3f68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 2 deletions

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);