The representation of an HTTP request, for any protocol version (HTTP/1.1, HTTP/2, HTTP/3).
The typical idiom to read request content is the following:
public boolean handle(Request request, Response response, Callback callback)
{
// Reject requests not appropriate for this handler.
if (!request.getHttpURI().getPath().startsWith("/yourPath"))
return false;
while (true)
{
Content.Chunk chunk = request.read();
if (chunk == null)
{
// The chunk is not currently available, demand to be called back.
request.demand(() -> handle(request, response, callback));
return true;
}
if (Content.Chunk.isError(chunk))
{
Throwable failure = error.getCause();
// Handle errors.
// If the chunk is not last, then the error can be ignored and reading can be tried again.
// Otherwise, if the chunk is last, or we do not wish to ignore a non-last error, then
// mark the handling as complete, either generating a custom
// response and succeeding the callback, or failing the callback.
callback.failed(failure);
return true;
}
if (chunk instanceof Trailers trailers)
{
HttpFields fields = trailers.getTrailers();
// Handle trailers.
// Generate a response.
// Mark the handling as complete.
callback.succeeded();
return true;
}
// Normal chunk, process it.
processChunk(chunk);
// Release the content after processing.
chunk.release();
// Reached end-of-file?
if (chunk.isLast())
{
// Generate a response.
// Mark the handling as complete.
callback.succeeded();
return true;
}
}
}
| Modifier and Type | Class and Description |
|---|---|
| public static class | Request.AttributesWrapper
A |
| public static interface | Request.AuthenticationState
A minimal Authentication interface, primarily used for logging. |
| public static interface | Request.Handler
A handler for an HTTP request and response. |
| public static interface | Request.ServeAs
This interface will be detected by the |
| public static class | Request.Wrapper
A wrapper for |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | |
| public static final String | |
| public static final List | |
| public static final Logger |
| Modifier and Type | Method and Description |
|---|---|
| public static void | addCompletionListener(Request request, Consumer<Throwable> listener)
Adds a completion listener that is an optimized equivalent to overriding the
|
| public void | addFailureListener(Consumer<Throwable>
the failure listener as a consumer function onFailure)Adds a listener for asynchronous fatal failures. |
| public void | addHttpStreamWrapper(Function<HttpStream, HttpStream>
A function that wraps the passed stream. wrapper)Add a |
| public void | addIdleTimeoutListener(Predicate<TimeoutException>
the idle timeout listener as a predicate function onIdleTimeout)Adds a listener for idle timeouts. |
| public static <T> T | |
| public static InputStream | |
| public static Request | Returns: a copy of the requestReturns a copy of the request that throws |
| public boolean | |
| public void | demand(Runnable
the demand callback to invoke when there is a content chunk available. demandCallback)Redeclares org. Demands to invoke the given demand callback parameter when a chunk of content is available. |
| public static Fields | |
| public static Fields | |
| public static <T, R> R | |
| public static Request. | Returns: the minimalAuthenticationState of the request, or null if no authentication in process.The request to enquire. request)
|
| public long | Returns: The nanoTime at which the request was received/created in nanosecondsGet the nanoTime at which the request arrived to a connector, obtained via |
| public static Charset | Returns: ACharset or nullThe request. request)Get a |
| public Components | |
| public ConnectionMetaData | |
| public static long | |
| public Context | |
| public static String | getContextPath(Request
The request to get the context path from. request)Get the context path of this |
| public static List | |
| public HttpFields | |
| public long | Returns: The nanoTime at which the request was ready in nanosecondsGet the nanoTime at which the request headers were parsed, obtained via |
| public static String | |
| public HttpURI | |
| public String | |
| public static String | |
| public static List | |
| public static int | |
| public String | |
| public static Fields | |
| public static CompletableFuture | |
| public static String | Returns: The part of the canonically encoded path of the URI after any context path prefix has been removed.Returns the canonically encoded path of the URI, scoped to the current context. |
| public static String | |
| public static int | |
| public static String | Returns: The logical server name or null if it cannot be determined.The request to get the server name of request)Get the logical name the request was sent to, which may be from the authority of the request; the configured server authority; the actual network name of the server; |
| public static int | Returns: The port for the request if it can be determined, otherwise -1The request to get the port of request)Get the logical port a request was received on, which may be from the authority of the request; the configured server authority; the default port for the scheme; or the actual network port. |
| public Session | Returns: The session associated with the request ornull.True if the session should be created for the request. create)Get a |
| public static long | Returns: The timestamp that the request was received/created in millisecondsGet the millisecond timestamp at which the request was created, obtained with |
| public HttpFields | |
| public TunnelSupport | |
| public boolean | |
| public static HttpURI | Returns: A new immutable HttpURI with the path in context replaced, but query string and path parameters retained.The request to base the new HttpURI on. request, String The new path in context for the new HttpURI newEncodedPathInContext)Creates a new |
| public default void | |
| public Content. | |
| public static Request | |
| public static void | setAuthenticationState(Request
The request to enquire. request, Request.the stateAuthenticationState of the request, or null if no authentication in process.
|
| public static String | Returns: the full redirect "Location" URL (including scheme, host, port, path, etc...)the request the redirect should be based on (needed when relative locations are provided, so that
server name, scheme, port can be built out properly) request, String the location URL to redirect to (can be a relative path) location)
Deprecated
use
Generate a proper "Location" header for redirects.
Response#toRedirectURI(Request, String)
|
| public static Request |