Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaukov committed May 23, 2024
1 parent ecc45e9 commit 852b5b1
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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");

Expand Down Expand Up @@ -196,7 +197,7 @@ else if (charsets.contains(StandardCharsets.ISO_8859_1))
return false;
}

int bufferSize = getBufferSize(request);
int bufferSize = getBufferSize() <= 0 ? computeBufferSize(request) : getBufferSize();
RetainableByteBuffer buffer = request.getComponents().getByteBufferPool().acquire(bufferSize, false);

try
Expand Down Expand Up @@ -261,10 +262,10 @@ else if (charsets.contains(StandardCharsets.ISO_8859_1))
}
}

protected int getBufferSize(Request request)
protected int computeBufferSize(Request request)
{
int bufferSize = request.getConnectionMetaData().getHttpConfiguration().getOutputBufferSize();
bufferSize = Math.min(8192, bufferSize); // TODO ?
bufferSize = Math.min(8192, bufferSize);
return bufferSize;
}

Expand Down Expand Up @@ -532,6 +533,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

0 comments on commit 852b5b1

Please sign in to comment.