Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable error page buffer size #11654

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class ErrorHandler implements Request.Handler
boolean _showStacks = false;
boolean _showCauses = false;
boolean _showMessageInTitle = true;
int _bufferSize = -1;
gregw marked this conversation as resolved.
Show resolved Hide resolved
String _defaultResponseMimeType = Type.TEXT_HTML.asString();
HttpField _cacheControl = new PreEncodedHttpField(HttpHeader.CACHE_CONTROL, "must-revalidate,no-cache,no-store");

Expand Down Expand Up @@ -198,8 +199,7 @@ else if (charsets.contains(StandardCharsets.ISO_8859_1))
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);

Expand Down Expand Up @@ -266,6 +266,13 @@ else if (charsets.contains(StandardCharsets.ISO_8859_1))
}
}

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)
Expand Down Expand Up @@ -530,6 +537,25 @@ public static Request.Handler getErrorHandler(Server server, ContextHandler cont
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);
Expand Down
Loading