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

Returns:

this request object
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
)

public Request

Returns:

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

public Request

Returns:

this request object
attribute
(String
the name of the attribute
name
,
Object
the value of the attribute
value
)

public Request

Returns:

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

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

Returns:

this request object
followRedirects
(boolean
whether this request follows redirects
follow
)

public Throwable

Returns:

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

public String

Returns:

the user agent for this request
getAgent
()

public Map<String, Object>

Returns:

the attributes of this request
getAttributes
()

public Request.Content

Returns:

the request content of this request
getBody
()

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>

Returns:

the cookies associated with this request
getCookies
()

public HttpFields

Returns:

the headers of this request
getHeaders
()

public String

Returns:

the URI host of this request, such as "127.0.0.1" or "google.com"
getHost
()

public long

Returns:

the idle timeout for this request, in milliseconds
getIdleTimeout
()

public String

Returns:

the method of this request, such as GET or POST, as a String
getMethod
()

public Fields

Returns:

the URI query parameters of this request
getParams
()

public String

Returns:

the URI path of this request, such as "/" or "/path" - without the query
getPath
()

public int

Returns:

the URI port of this request such as 80 or 443
getPort
()

public String

Returns:

the URI query string of this request such as "param=1"
getQuery
()

public String

Returns:

the URI scheme of this request, such as "http" or "https"
getScheme
()

public Object

Returns:

the metadata this request has been tagged with
getTag
()

public long

Returns:

the total timeout for this request, in milliseconds; zero or negative if the timeout is disabled
getTimeout
()

public Supplier<HttpFields>

Returns:

the supplier of the trailers of this request
getTrailersSupplier
()

public URI

Returns:

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

public HttpVersion

Returns:

the HTTP version of this request, such as "HTTP/1.1"
getVersion
()

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

Returns:

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

public Request

Returns:

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

public boolean

Returns:

whether this request follows redirects
isFollowRedirects
()

public Request

Returns:

this request object
listener
(Request.Listener
a listener for request events
listener
)

public Request

Returns:

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

public Request

Returns:

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

public Request

Returns:

this request object
onComplete
(Response.CompleteListener
a listener for complete event
listener
)

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

Returns:

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

public Request

Returns:

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

public Request

Returns:

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

public Request

Returns:

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

public Request

Returns:

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

public Request

Returns:

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

public Request

Returns:

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

public Request

Returns:

this request object
onResponseBegin
(Response.BeginListener
a listener for response begin event
listener
)

public Request

Returns:

this request object
onResponseContent
(Response.ContentListener
a consuming listener for response content events
listener
)

public Request

Returns:

this request object
onResponseContentAsync
(Response.AsyncContentListener
an asynchronous listener for response content events
listener
)

public Request

Returns:

this request object
onResponseContentSource
(Response.ContentSourceListener listener)

public Request

Returns:

this request object
onResponseFailure
(Response.FailureListener
a listener for response failure event
listener
)

public Request

Returns:

this request object
onResponseHeader
(Response.HeaderListener
a listener for response header event
listener
)

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

Returns:

this request object
onResponseSuccess
(Response.SuccessListener
a listener for response success event
listener
)

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

Returns:

this request object
port
(int
the URI port of this request such as 80 or 443
port
)

public Request

Returns:

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

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

Returns:

this request object
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
)

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

Returns:

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