Top Description Inners Methods
org.eclipse.jetty.client

public Interface Request

Known Direct Implementers
org.eclipse.jetty.client.transport.HttpRequest
Imports
java.io.IOException, java.net.URI, .URLEncoder, java.nio.ByteBuffer, java.nio.file.Path, java.util.EventListener, .List, .Map, java.util.concurrent.CompletableFuture, .ExecutionException, .TimeUnit, .TimeoutException, java.util.function.BiFunction, .Consumer, .Supplier, org.eclipse.jetty.http.HttpCookie, .HttpFields, .HttpMethod, .HttpVersion, org.eclipse.jetty.util.Fields

Request represents an HTTP request, and offers a fluent interface to customize various attributes such as the path, the headers, the content, etc.

You can create Request objects via HttpClient#newRequest(String) and you can send them using either send() for a blocking semantic, or send(Response.CompleteListener) for an asynchronous semantic.

Request objects cannot be reused for other requests, not even for requests that have identical URI and headers.

See Also
Response

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Request.BeginListener

Listener for the request begin event.

public static interface
Request.CommitListener

Listener for the request committed event.

public static interface
Request.Content

A client-side representation of HTTP request content.

public static interface
Request.ContentListener

Listener for the request content event.

public static interface
Request.FailureListener

Listener for the request failed event.

public static interface
Request.HeadersListener

Listener for the request headers event.

public static interface
Request.Listener

Listener for all request events.

public static interface
Request.QueuedListener

Listener for the request queued event.

public static interface
Request.RequestListener

Common, empty, super-interface for request listeners.

public static interface
Request.SuccessListener

Listener for the request succeeded event.

Method Summary

Modifier and TypeMethod and Description
public CompletableFuture<Boolean>

Returns:

whether the abort succeeded
abort
(Throwable
the abort cause, must not be null
cause
)

Attempts to abort the send of this request.

public Request
accept(String...
the media types that are acceptable in the response, such as "text/plain;q=0.5" or "text/html" (corresponds to the Accept header)
accepts
)

Returns: this request object

public Request
agent(String
the user agent for this request (corresponds to the User-Agent header)
agent
)

Returns: this request object

public Request
attribute(String
the name of the attribute
name
,
Object
the value of the attribute
value
)

Returns: this request object

public Request
body(Request.Content
the request content of this request
content
)

Returns: this request object

public Request

Returns:

this request object
file
(Path
the file to upload
file
)

Shortcut method to specify a file as a content for this request, with the default content type of "application/octet-stream".

public Request

Returns:

this request object
file
(Path
the file to upload
file
,
String
the content type of the file
contentType
)

Shortcut method to specify a file as a content for this request, with the given content type.

public Request
followRedirects(boolean
whether this request follows redirects
follow
)

Returns: this request object

public Throwable
getAbortCause()

Returns: the abort cause passed to abort(Throwable), or null if this request has not been aborted

public String
getAgent()

Returns: the user agent for this request

public Map<String, Object>
getAttributes()

Returns: the attributes of this request

public Request.Content
getBody()

Returns: the request content of this request

public default Connection

Returns:

the connection associated with this request, or null if there is no connection associated with this request
getConnection
()

Returns the connection associated with this request.

public List<HttpCookie>
getCookies()

Returns: the cookies associated with this request

public HttpFields
getHeaders()

Returns: the headers of this request

public String
getHost()

Returns: the URI host of this request, such as "127.0.0.1" or "google.com"

public long
getIdleTimeout()

Returns: the idle timeout for this request, in milliseconds

public String
getMethod()

Returns: the method of this request, such as GET or POST, as a String

public Fields
getParams()

Returns: the URI query parameters of this request

public String
getPath()

Returns: the URI path of this request, such as "/" or "/path" - without the query

public int
getPort()

Returns: the URI port of this request such as 80 or 443

public String
getQuery()

Returns: the URI query string of this request such as "param=1"

public String
getScheme()

Returns: the URI scheme of this request, such as "http" or "https"

public Object
getTag()

Returns: the metadata this request has been tagged with

public long
getTimeout()

Returns: the total timeout for this request, in milliseconds; zero or negative if the timeout is disabled

public Supplier<HttpFields>
getTrailersSupplier()

Returns: the supplier of the trailers of this request

public URI
getURI()

Returns: the full URI of this request such as https://host:port/path?param=1

public HttpVersion
getVersion()

Returns: the HTTP version of this request, such as "HTTP/1.1"

public Request

Returns:

this request object
headers
(Consumer<HttpFields.Mutable>
the code that modifies the headers of this request
consumer
)

Modifies the headers of this request.

public default Request
host(String
the URI host of this request, such as "127.0.0.1" or "google.com"
host
)

Returns: this request object

public Request
idleTimeout(long
the idle timeout for this request
timeout
,
TimeUnit
the idle timeout unit
unit
)

Returns: this request object

public boolean
isFollowRedirects()

Returns: whether this request follows redirects

public Request
listener(Request.Listener
a listener for request events
listener
)

Returns: this request object

public Request
method(HttpMethod
the method of this request, such as GET or POST
method
)

Returns: this request object

public Request
method(String
the method of this request, such as GET or POST
method
)

Returns: this request object

public Request
onComplete(Response.CompleteListener
a listener for complete event
listener
)

Returns: this request object

public Request

Returns:

this request object
onPush
(BiFunction<Request, Request, Response.CompleteListener>
a handler for pushed resource events
pushHandler
)

Sets a handler for pushed resources.

public Request
onRequestBegin(Request.BeginListener
a listener for request begin event
listener
)

Returns: this request object

public Request
onRequestCommit(Request.CommitListener
a listener for request commit event
listener
)

Returns: this request object

public Request
onRequestContent(Request.ContentListener
a listener for request content events
listener
)

Returns: this request object

public Request
onRequestFailure(Request.FailureListener
a listener for request failure event
listener
)

Returns: this request object

public Request
onRequestHeaders(Request.HeadersListener
a listener for request headers event
listener
)

Returns: this request object

public Request
onRequestQueued(Request.QueuedListener
a listener for request queued event
listener
)

Returns: this request object

public Request
onRequestSuccess(Request.SuccessListener
a listener for request success event
listener
)

Returns: this request object

public Request
onResponseBegin(Response.BeginListener
a listener for response begin event
listener
)

Returns: this request object

public Request
onResponseContent(Response.ContentListener
a consuming listener for response content events
listener
)

Returns: this request object

public Request
onResponseContentAsync(Response.AsyncContentListener
an asynchronous listener for response content events
listener
)

Returns: this request object

public Request
onResponseContentSource(Response.ContentSourceListener listener)

Returns: this request object

public Request
onResponseFailure(Response.FailureListener
a listener for response failure event
listener
)

Returns: this request object

public Request
onResponseHeader(Response.HeaderListener
a listener for response header event
listener
)

Returns: this request object

public Request

Returns:

this request object
onResponseHeaders
(Response.HeadersListener
a listener for response headers event
listener
)

Registers a listener for the headers event.

public Request
onResponseSuccess(Response.SuccessListener
a listener for response success event
listener
)

Returns: this request object

public Request

Returns:

this request object
param
(String
the name of the query parameter
name
,
String
the value of the query parameter
value
)

Adds a URI query parameter with the given name and value.

public Request

Returns:

this request object
path
(String
the URI path of this request, such as "/" or "/path?param=1"
path
)

Specifies the URI path - and possibly the query - of this request.

public default Request
port(int
the URI port of this request such as 80 or 443
port
)

Returns: this request object

public Request
scheme(String
the URI scheme of this request, such as "http" or "https"
scheme
)

Returns: this request object

public ContentResponse

Returns:

a ContentResponse for this request
send
()

Sends this request and returns the response.

public void
send(Response.CompleteListener
the listener that receives response events
listener
)

Sends this request and asynchronously notifies the given listener for response events.

public Request

Returns:

this request object
tag
(Object
the metadata to tag the request with
tag
)

Tags this request with the given metadata tag.

public Request
timeout(long
the total timeout for the request/response conversation; use zero or a negative value to disable the timeout
timeout
,
TimeUnit
the timeout unit
unit
)

Returns: this request object

public Request

Returns:

this request object
trailersSupplier
(Supplier<HttpFields>
the supplier of the trailers of this request
trailers
)

Provides the trailers of this request.

public Request
version(HttpVersion
the HTTP version of this request, such as "HTTP/1.1"
version
)

Returns: this request object