Top Description Inners Fields Methods
org.eclipse.jetty.server

public Interface Request

extends Attributes, Source
Known Direct Subinterfaces
org.eclipse.jetty.server.Request.ServeAs
Known Direct Implementers
org.eclipse.jetty.server.Request.Wrapper, org.eclipse.jetty.server.internal.HttpChannelState.ChannelRequest
Imports
java.io.InputStream, java.net.InetAddress, .InetSocketAddress, .SocketAddress, java.nio.ByteBuffer, java.nio.charset.Charset, .IllegalCharsetNameException, .UnsupportedCharsetException, java.security.Principal, java.util.ArrayList, .List, .Locale, .Map, .Objects, .Set, java.util.concurrent.CompletableFuture, .TimeoutException, java.util.function.Consumer, .Function, .Predicate, org.eclipse.jetty.http.CookieCache, .HttpCookie, .HttpFields, .HttpHeader, .HttpScheme, .HttpURI, .MetaData, .MimeTypes, .Trailers, org.eclipse.jetty.io.Content, org.eclipse.jetty.server.internal.CompletionStreamWrapper, .HttpChannelState, org.eclipse.jetty.util.Attributes, .Callback, .Fields, .HostPort, .NanoTime, .StringUtil, .URIUtil, .UrlEncoded, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.thread.Invocable, org.slf4j.Logger, .LoggerFactory

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Request.AttributesWrapper

A Request.Wrapper that separately provides the request Attributes.

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 wrap(Request, HttpURI) static method to wrap the request changing its target to a given path.

public static class
Request.Wrapper

A wrapper for Request instances.

Field Summary

Modifier and TypeField and Description
public static final String
public static final List<Locale>
public static final Logger
Inherited from org.eclipse.jetty.util.Attributes:
NULL

Method Summary

Modifier and TypeMethod and Description
public static void
addCompletionListener(Request request, Consumer<Throwable>
A Consumer of Throwable to call when the request handling is complete. The listener is passed a null Throwable on success.
listener
)

Adds a completion listener that is an optimized equivalent to overriding the HttpStream#succeeded() and HttpStream#failed(Throwable) methods of a HttpStream.Wrapper created by a call to addHttpStreamWrapper(Function).

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 HttpStream.Wrapper to the current HttpStream.

public void
addIdleTimeoutListener(Predicate<TimeoutException>
the idle timeout listener as a predicate function
onIdleTimeout
)

Adds a listener for idle timeouts.

public static <T> T
as(Request request, Class<T> type)

public static InputStream
public static Request

Returns:

a copy of the request
asReadOnly
(Request request)

Returns a copy of the request that throws UnsupportedOperationException from all mutative methods.

public boolean

Returns:

true if the content was fully consumed.
consumeAvailable
()

Consume any available content.

public void
demand(Runnable
the demand callback to invoke when there is a content chunk available.
demandCallback
)

Redeclares org.eclipse.jetty.io.Content.Source.demand.

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
get(Request request, Class<T> type, Function<T, R> getter)

public static Request.AuthenticationState

Returns:

the minimal AuthenticationState of the request, or null if no authentication in process.
getAuthenticationState
(Request
The request to enquire.
request
)

public long

Returns:

The nanoTime at which the request was received/created in nanoseconds
getBeginNanoTime
()

Get the nanoTime at which the request arrived to a connector, obtained via System#nanoTime().

public static Charset

Returns:

A Charset or null
getCharset
(Request
The request.
request
)

Get a Charset from the request HttpHeader#CONTENT_TYPE, if any.

public Components

Returns:

the Components to be used with this Request.
getComponents
()

public ConnectionMetaData

Returns:

the ConnectionMetaData associated to this Request
getConnectionMetaData
()

public static long
public Context

Returns:

the Context associated with this Request. Never null.
getContext
()

Get the Context associated with this Request.

public static String

Returns:

The encoded context path of the Context or null.
getContextPath
(Request
The request to get the context path from.
request
)

Get the context path of this Request.

public static List<HttpCookie>
public HttpFields

Returns:

the HTTP headers of this Request
getHeaders
()

public long

Returns:

The nanoTime at which the request was ready in nanoseconds
getHeadersNanoTime
()

Get the nanoTime at which the request headers were parsed, obtained via System#nanoTime().

public static String
getHostName(InetSocketAddress inetSocketAddress)

public HttpURI

Returns:

the HTTP URI of this Request
getHttpURI
()

public String
getId()

an ID unique within the lifetime scope of the ConnectionMetaData#getId()).

public static String
public static List<Locale>
public static int
public String

Returns:

the HTTP method of this Request
getMethod
()

public static Fields
public static CompletableFuture<Fields>
public static String

Returns:

The part of the canonically encoded path of the URI after any context path prefix has been removed.
getPathInContext
(Request request)

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.
getServerName
(Request
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 -1
getServerPort
(Request
The 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 or null.
getSession
(boolean
True if the session should be created for the request.
create
)

Get a Session associated with the request.

public static long

Returns:

The timestamp that the request was received/created in milliseconds
getTimeStamp
(Request request)

Get the millisecond timestamp at which the request was created, obtained with System#currentTimeMillis().

public HttpFields

Returns:

the HTTP trailers of this Request, or null if they are not present
getTrailers
()

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.
newHttpURIFrom
(Request
The request to base the new HttpURI on.
request
,
String
The new path in context for the new HttpURI
newEncodedPathInContext
)

Creates a new HttpURI from the given Request's HttpURI and the given path in context.

public default void
push(MetaData.Request
the resource to push
resource
)

Pushes the given resource to the client.

public Content.Chunk
read()

Redeclares org.eclipse.jetty.io.Content.Source.read.

Reads a chunk of content.

public static Request

Returns:

the possibly wrapped request to target the new URI.
serveAs
(Request
the original request.
request
,
HttpURI
the new URI to target.
uri
)

Return a request with its HttpURI changed to the supplied target.

public static void
setAuthenticationState(Request
The request to enquire.
request
,
Request.AuthenticationState
the AuthenticationState of the request, or null if no authentication in process.
state
)

public static String

Returns:

the full redirect "Location" URL (including scheme, host, port, path, etc...)
toRedirectURI
(Request
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
)

Generate a proper "Location" header for redirects.
public static Request
unWrap(Request request)

Inherited from org.eclipse.jetty.io.Content.Source:
asByteArrayAsyncasByteBufferasByteBufferasByteBufferAsyncasByteBufferAsyncasInputStreamasPublisherasRetainableByteBufferasStringasStringasStringasStringAsyncconsumeAllconsumeAllfailfailgetLengthrewind
Inherited from org.eclipse.jetty.util.Attributes:
asAttributeMapclearAttributesequalsequalsgetAttributegetAttributeNameSethashCodehashCoderemoveAttributesetAttributeunwrapunwrap