A Handler that can limit the size of message bodies in requests and responses.
The optional request and response limits are imposed by checking the Content-Length
header or observing the actual bytes seen by this Handler.
Handler order is important; for example, if this handler is before the GzipHandler,
then it will limit compressed sizes, if it as after the GzipHandler then it will limit
uncompressed sizes.
If a size limit is exceeded then BadMessageException is thrown with a
HttpStatus#PAYLOAD_TOO_LARGE_413 status.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final long | |
| private final long |
| Access | Constructor and Description |
|---|---|
| public | SizeLimitHandler(long
The request body size limit in bytes or -1 for no limit requestLimit, long The response body size limit in bytes or -1 for no limit responseLimit)
|
| Modifier and Type | Method and Description |
|---|---|
| public boolean | handle(Request
the HTTP request to handle request, Response the HTTP response to handle response, Callback the callback to complete when the handling is complete callback)Overrides org. Implements org. Invoked to handle the passed HTTP request and response. |
| _requestLimit | back to summary |
|---|---|
| private final long _requestLimit | |
| _responseLimit | back to summary |
|---|---|
| private final long _responseLimit | |
| SizeLimitHandler | back to summary |
|---|---|
public SizeLimitHandler(long requestLimit, long responseLimit)
| |
| handle | back to summary |
|---|---|
| public boolean handle(Request request, Response response, Callback callback) throws Exception Overrides org. Implements org. Doc from org. Invoked to handle the passed HTTP request and response. The request is accepted by returning true, then handling must be concluded by completing the passed callback. The handling may be asynchronous, i.e. this method may return true and complete the given callback later, possibly from a different thread. If this method returns false, then the callback must not be invoked and any mutation on the response reversed. Exceptions thrown by this method may be subsequently handled by an error The simplest implementation is:
public boolean handle(Request request, Response response, Callback callback)
{
callback.succeeded();
return true;
}
A HelloWorld implementation is:
public boolean handle(Request request, Response response, Callback callback)
{
response.write(true, ByteBuffer.wrap("Hello World\n".getBytes(StandardCharsets.UTF_8)), callback);
return true;
}
| |
| Modifier and Type | Field and Description |
|---|---|
| private long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Content. | read()
Overrides org. Implements org. Reads a chunk of content. |
| _read | back to summary |
|---|---|
| private long _read | |
| SizeLimitRequestWrapper | back to summary |
|---|---|
| public SizeLimitRequestWrapper(Request wrapped) | |
| read | back to summary |
|---|---|
| public Content. Overrides org. Implements org. Doc from org. Reads a chunk of content. See how to use this method idiomatically. The returned chunk could be:
Once a read returns an Once a read returns a The content reader code must ultimately arrange for a call to
Additionally, prior to the ultimate call to Concurrent reads from different threads are not recommended, as they are inherently in a race condition. Reads performed outside the invocation context of a
In addition, the returned
| |
| Modifier and Type | Field and Description |
|---|---|
| private final HttpFields. | |
| private long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public HttpFields. | |
| public void | write(boolean
whether the ByteBuffer is the last to write last, ByteBuffer the ByteBuffer to write content, Callback the callback to notify when the write operation is complete callback)Overrides org. Implements org. Writes the given |
| _httpFields | back to summary |
|---|---|
| private final HttpFields. | |
| _written | back to summary |
|---|---|
| private long _written | |
| SizeLimitResponseWrapper | back to summary |
|---|---|
| public SizeLimitResponseWrapper(Request request, Response wrapped) | |
| getHeaders | back to summary |
|---|---|
| public HttpFields. Overrides org. Implements org.
| |
| write | back to summary |
|---|---|
| public void write(boolean last, ByteBuffer content, Callback callback) Overrides org. Implements org. Doc from org. Writes the given Implementations guarantee that calls to this method are safely reentrant so that
stack overflows are avoided in the case of mutual recursion between the execution of
the The invocation of the passed Thus a
| |