Class HttpRequest
- All Implemented Interfaces:
Request
- Direct Known Subclasses:
TunnelRequest
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.Request
Request.BeginListener, Request.CommitListener, Request.Content, Request.ContentListener, Request.FailureListener, Request.HeadersListener, Request.Listener, Request.QueuedListener, Request.RequestListener, Request.SuccessListener
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAttempts to abort the send of this request.body
(Request.Content content) cookie
(HttpCookie cookie) protected HttpRequest
copyInstance
(URI newURI) Shortcut method to specify a file as a content for this request, with the default content type of "application/octet-stream".Shortcut method to specify a file as a content for this request, with the given content type.followRedirects
(boolean follow) getAgent()
getBody()
Returns the connection associated with this request.getHost()
protected HttpClient
long
getPath()
int
getPort()
getQuery()
getTag()
long
long
getURI()
headers
(Consumer<HttpFields.Mutable> consumer) Modifies the headers of this request.idleTimeout
(long timeout, TimeUnit unit) boolean
boolean
listener
(Request.Listener listener) method
(HttpMethod method) void
void
void
notifyContent
(ByteBuffer byteBuffer) void
notifyFailure
(Throwable failure) void
void
void
onComplete
(Response.CompleteListener listener) onPush
(BiFunction<Request, Request, Response.CompleteListener> pushHandler) Sets a handler for pushed resources.onRequestBegin
(Request.BeginListener listener) onRequestCommit
(Request.CommitListener listener) onRequestContent
(Request.ContentListener listener) onRequestFailure
(Request.FailureListener listener) onRequestHeaders
(Request.HeadersListener listener) onRequestQueued
(Request.QueuedListener listener) onRequestSuccess
(Request.SuccessListener listener) onResponseBegin
(Response.BeginListener listener) onResponseContent
(Response.ContentListener listener) onResponseFailure
(Response.FailureListener listener) onResponseHeader
(Response.HeaderListener listener) onResponseHeaders
(Response.HeadersListener listener) Registers a listener for the headers event.onResponseSuccess
(Response.SuccessListener listener) Adds a URI query parameter with the given name and value.Specifies the URI path - and possibly the query - of this request.port
(int port) send()
Sends this request and returns the response.void
send
(Response.CompleteListener listener) Sends this request and asynchronously notifies the given listener for response events.Tags this request with the given metadata tag.toString()
trailersSupplier
(Supplier<HttpFields> trailers) Provides the trailers of this request.version
(HttpVersion version)
-
Constructor Details
-
HttpRequest
-
-
Method Details
-
copy
-
copyInstance
-
getHttpClient
-
getConversation
-
getConnection
Description copied from interface:Request
Returns the connection associated with this request.
The connection is available only starting from the
request begin
event, when a connection is associated with the request to be sent, otherwisenull
is returned.- Specified by:
getConnection
in interfaceRequest
- Returns:
- the connection associated with this request,
or
null
if there is no connection associated with this request
-
getScheme
-
scheme
-
getHost
-
host
-
getPort
public int getPort() -
port
-
transport
-
getTransport
- Specified by:
getTransport
in interfaceRequest
- Returns:
- the
Transport
of this request
-
getMethod
-
method
-
method
-
getPath
-
path
Description copied from interface:Request
Specifies the URI path - and possibly the query - of this request. If the query part is specified, parameter values must be properlyUTF-8 URL encoded
. For example, if the value for parameter "currency" is the euro symbol € then the query string for this parameter must be "currency=%E2%82%AC". For transparent encoding of parameter values, useRequest.param(String, String)
. -
getQuery
-
getURI
-
getVersion
- Specified by:
getVersion
in interfaceRequest
- Returns:
- the HTTP version of this request, such as "HTTP/1.1"
-
isVersionExplicit
public boolean isVersionExplicit() -
version
-
param
Description copied from interface:Request
Adds a URI query parameter with the given name and value. The value isUTF-8 URL encoded
. -
getParams
-
getAgent
-
agent
-
accept
-
getCookies
- Specified by:
getCookies
in interfaceRequest
- Returns:
- the cookies associated with this request
-
cookie
-
tag
Description copied from interface:Request
Tags this request with the given metadata tag.
Each different tag will create a different destination, even if the destination origin is the same.
This is particularly useful in proxies, where requests for the same origin but from different clients may be tagged with client's metadata (e.g. the client remote address).
The tag metadata class must correctly implement
Object.hashCode()
andObject.equals(Object)
so that it can be used, along with the origin, to identify a destination. -
getTag
-
attribute
-
getAttributes
- Specified by:
getAttributes
in interfaceRequest
- Returns:
- the attributes of this request
-
getHeaders
- Specified by:
getHeaders
in interfaceRequest
- Returns:
- the headers of this request
-
headers
Description copied from interface:Request
Modifies the headers of this request. -
addHeader
-
listener
-
onRequestQueued
- Specified by:
onRequestQueued
in interfaceRequest
- Parameters:
listener
- a listener for request queued event- Returns:
- this request object
-
notifyQueued
public void notifyQueued() -
onRequestBegin
- Specified by:
onRequestBegin
in interfaceRequest
- Parameters:
listener
- a listener for request begin event- Returns:
- this request object
-
notifyBegin
public void notifyBegin() -
onRequestHeaders
- Specified by:
onRequestHeaders
in interfaceRequest
- Parameters:
listener
- a listener for request headers event- Returns:
- this request object
-
notifyHeaders
public void notifyHeaders() -
onRequestCommit
- Specified by:
onRequestCommit
in interfaceRequest
- Parameters:
listener
- a listener for request commit event- Returns:
- this request object
-
notifyCommit
public void notifyCommit() -
onRequestContent
- Specified by:
onRequestContent
in interfaceRequest
- Parameters:
listener
- a listener for request content events- Returns:
- this request object
-
notifyContent
-
onRequestSuccess
- Specified by:
onRequestSuccess
in interfaceRequest
- Parameters:
listener
- a listener for request success event- Returns:
- this request object
-
notifySuccess
public void notifySuccess() -
onRequestFailure
- Specified by:
onRequestFailure
in interfaceRequest
- Parameters:
listener
- a listener for request failure event- Returns:
- this request object
-
notifyFailure
-
onResponseBegin
- Specified by:
onResponseBegin
in interfaceRequest
- Parameters:
listener
- a listener for response begin event- Returns:
- this request object
-
onResponseHeader
- Specified by:
onResponseHeader
in interfaceRequest
- Parameters:
listener
- a listener for response header event- Returns:
- this request object
-
onResponseHeaders
Description copied from interface:Request
Registers a listener for the headers event.
Note that the response headers at this event may be different from the headers received in
Request.onResponseHeader(Response.HeaderListener)
as specified inResponse.getHeaders()
.- Specified by:
onResponseHeaders
in interfaceRequest
- Parameters:
listener
- a listener for response headers event- Returns:
- this request object
-
onResponseContent
- Specified by:
onResponseContent
in interfaceRequest
- Parameters:
listener
- a consuming listener for response content events- Returns:
- this request object
-
onResponseContentAsync
- Specified by:
onResponseContentAsync
in interfaceRequest
- Parameters:
listener
- an asynchronous listener for response content events- Returns:
- this request object
-
onResponseContentSource
- Specified by:
onResponseContentSource
in interfaceRequest
- Parameters:
listener
- a listener for drivingContent.Source
- Returns:
- this request object
-
onResponseSuccess
- Specified by:
onResponseSuccess
in interfaceRequest
- Parameters:
listener
- a listener for response success event- Returns:
- this request object
-
onResponseFailure
- Specified by:
onResponseFailure
in interfaceRequest
- Parameters:
listener
- a listener for response failure event- Returns:
- this request object
-
onPush
Description copied from interface:Request
Sets a handler for pushed resources.
When resources are pushed from the server, the given
pushHandler
is invoked for every pushed resource. The parameters to theBiFunction
are this request and the synthesized request for the pushed resource. TheBiFunction
should return aCompleteListener
that may also implement other listener interfaces to be notified of various response events, ornull
to signal that the pushed resource should be canceled. -
onComplete
- Specified by:
onComplete
in interfaceRequest
- Parameters:
listener
- a listener for complete event- Returns:
- this request object
-
trailersSupplier
Description copied from interface:Request
Provides the trailers of this request.- Specified by:
trailersSupplier
in interfaceRequest
- Parameters:
trailers
- the supplier of the trailers of this request- Returns:
- this request object
-
getBody
-
body
-
file
Description copied from interface:Request
Shortcut method to specify a file as a content for this request, with the default content type of "application/octet-stream".- Specified by:
file
in interfaceRequest
- Parameters:
file
- the file to upload- Returns:
- this request object
- Throws:
IOException
- if the file does not exist or cannot be read
-
file
Description copied from interface:Request
Shortcut method to specify a file as a content for this request, with the given content type.- Specified by:
file
in interfaceRequest
- Parameters:
file
- the file to uploadcontentType
- the content type of the file- Returns:
- this request object
- Throws:
IOException
- if the file does not exist or cannot be read
-
isFollowRedirects
public boolean isFollowRedirects()- Specified by:
isFollowRedirects
in interfaceRequest
- Returns:
- whether this request follows redirects
-
followRedirects
- Specified by:
followRedirects
in interfaceRequest
- Parameters:
follow
- whether this request follows redirects- Returns:
- this request object
-
getIdleTimeout
public long getIdleTimeout()- Specified by:
getIdleTimeout
in interfaceRequest
- Returns:
- the idle timeout for this request, in milliseconds
-
idleTimeout
- Specified by:
idleTimeout
in interfaceRequest
- Parameters:
timeout
- the idle timeout for this requestunit
- the idle timeout unit- Returns:
- this request object
-
getTimeout
public long getTimeout()- Specified by:
getTimeout
in interfaceRequest
- Returns:
- the total timeout for this request, in milliseconds; zero or negative if the timeout is disabled
-
timeout
-
send
Description copied from interface:Request
Sends this request and returns the response.This method should be used when a simple blocking semantic is needed, and when it is known that the response content can be buffered without exceeding memory constraints.
For example, this method is not appropriate to download big files from a server; consider using
Request.send(Response.CompleteListener)
instead, passing your ownResponse.Listener
or a utility listener such asInputStreamResponseListener
.The method returns when the
complete event
is fired.- Specified by:
send
in interfaceRequest
- Returns:
- a
ContentResponse
for this request - Throws:
InterruptedException
- if send thread is interruptedTimeoutException
- if send times outExecutionException
- if execution fails- See Also:
-
send
Description copied from interface:Request
Sends this request and asynchronously notifies the given listener for response events.
This method should be used when the application needs to be notified of the various response events as they happen, or when the application needs to efficiently manage the response content.
The listener passed to this method may implement not only
Response.CompleteListener
but also other response listener interfaces, and all the events implemented will be notified. This allows application code to write a single listener class to handle all relevant events. -
getTimeoutNanoTime
public long getTimeoutNanoTime()- Returns:
- The nanoTime at which the timeout expires or
Long.MAX_VALUE
if there is no timeout. - See Also:
-
getResponseListeners
-
getPushHandler
-
getTrailersSupplier
- Specified by:
getTrailersSupplier
in interfaceRequest
- Returns:
- the supplier of the trailers of this request
-
abort
Description copied from interface:Request
Attempts to abort the send of this request. -
getAbortCause
- Specified by:
getAbortCause
in interfaceRequest
- Returns:
- the abort cause passed to
Request.abort(Throwable)
, or null if this request has not been aborted
-
toString
-