Class HttpRequest
- All Implemented Interfaces:
Request
-
Nested Class Summary
Nested classes/interfaces inherited from interface Request
Request.BeginListener, Request.CommitListener, Request.Content, Request.ContentListener, Request.FailureListener, Request.HeadersListener, Request.Listener, Request.QueuedListener, Request.RequestListener, Request.SuccessListener -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAttempts to abort the send of this request.body(Request.Content content) cookie(HttpCookie cookie) protected HttpRequestcopyInstance(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 HttpClientlonggetPath()intgetPort()getQuery()getTag()longlonggetURI()headers(Consumer<HttpFields.Mutable> consumer) Modifies the headers of this request.idleTimeout(long timeout, TimeUnit unit) booleanbooleanmethod(HttpMethod method) voidvoidvoidnotifyContent(ByteBuffer byteBuffer) voidnotifyFailure(Throwable failure) voidvoidvoidonComplete(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) onRequestListener(Request.Listener 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.onResponseListener(Response.Listener listener) 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.voidsend(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:RequestReturns the connection associated with this request.
The connection is available only starting from the
request beginevent, when a connection is associated with the request to be sent, otherwisenullis returned.- Specified by:
getConnectionin interfaceRequest- Returns:
- the connection associated with this request,
or
nullif there is no connection associated with this request
-
getScheme
-
scheme
-
getHost
-
host
-
getPort
-
port
-
transport
-
getTransport
- Specified by:
getTransportin interfaceRequest- Returns:
- the
Transportof this request
-
getMethod
-
method
-
method
-
getPath
-
path
Description copied from interface:RequestSpecifies 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:
getVersionin interfaceRequest- Returns:
- the HTTP version of this request, such as "HTTP/1.1"
-
isVersionExplicit
public boolean isVersionExplicit() -
version
-
param
Description copied from interface:RequestAdds a URI query parameter with the given name and value. The value isUTF-8 URL encoded. -
getParams
-
getAgent
-
agent
-
accept
-
getCookies
- Specified by:
getCookiesin interfaceRequest- Returns:
- the cookies associated with this request
-
cookie
-
tag
Description copied from interface:RequestTags 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:
getAttributesin interfaceRequest- Returns:
- the attributes of this request
-
getHeaders
- Specified by:
getHeadersin interfaceRequest- Returns:
- the headers of this request
-
headers
-
addHeader
-
onRequestListener
- Specified by:
onRequestListenerin interfaceRequest- Parameters:
listener- a listener for all request events- Returns:
- this request object
-
onRequestQueued
- Specified by:
onRequestQueuedin interfaceRequest- Parameters:
listener- a listener for request queued event- Returns:
- this request object
-
notifyQueued
public void notifyQueued() -
onRequestBegin
- Specified by:
onRequestBeginin interfaceRequest- Parameters:
listener- a listener for request begin event- Returns:
- this request object
-
notifyBegin
public void notifyBegin() -
onRequestHeaders
- Specified by:
onRequestHeadersin interfaceRequest- Parameters:
listener- a listener for request headers event- Returns:
- this request object
-
notifyHeaders
public void notifyHeaders() -
onRequestCommit
- Specified by:
onRequestCommitin interfaceRequest- Parameters:
listener- a listener for request commit event- Returns:
- this request object
-
notifyCommit
public void notifyCommit() -
onRequestContent
- Specified by:
onRequestContentin interfaceRequest- Parameters:
listener- a listener for request content events- Returns:
- this request object
-
notifyContent
-
onRequestSuccess
- Specified by:
onRequestSuccessin interfaceRequest- Parameters:
listener- a listener for request success event- Returns:
- this request object
-
notifySuccess
public void notifySuccess() -
onRequestFailure
- Specified by:
onRequestFailurein interfaceRequest- Parameters:
listener- a listener for request failure event- Returns:
- this request object
-
notifyFailure
-
onResponseListener
- Specified by:
onResponseListenerin interfaceRequest- Parameters:
listener- a listener for all response events- Returns:
- this request object
-
onResponseBegin
- Specified by:
onResponseBeginin interfaceRequest- Parameters:
listener- a listener for response begin event- Returns:
- this request object
-
onResponseHeader
- Specified by:
onResponseHeaderin interfaceRequest- Parameters:
listener- a listener for response header event- Returns:
- this request object
-
onResponseHeaders
Description copied from interface:RequestRegisters 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:
onResponseHeadersin interfaceRequest- Parameters:
listener- a listener for response headers event- Returns:
- this request object
-
onResponseContent
- Specified by:
onResponseContentin interfaceRequest- Parameters:
listener- a consuming listener for response content events- Returns:
- this request object
-
onResponseContentAsync
- Specified by:
onResponseContentAsyncin interfaceRequest- Parameters:
listener- an asynchronous listener for response content events- Returns:
- this request object
-
onResponseContentSource
- Specified by:
onResponseContentSourcein interfaceRequest- Parameters:
listener- a listener for drivingContent.Source- Returns:
- this request object
-
onResponseSuccess
- Specified by:
onResponseSuccessin interfaceRequest- Parameters:
listener- a listener for response success event- Returns:
- this request object
-
onResponseFailure
- Specified by:
onResponseFailurein interfaceRequest- Parameters:
listener- a listener for response failure event- Returns:
- this request object
-
onPush
Description copied from interface:RequestSets a handler for pushed resources.
When resources are pushed from the server, the given
pushHandleris invoked for every pushed resource. The parameters to theBiFunctionare this request and the synthesized request for the pushed resource. TheBiFunctionshould return aCompleteListenerthat may also implement other listener interfaces to be notified of various response events, ornullto signal that the pushed resource should be canceled. -
onComplete
- Specified by:
onCompletein interfaceRequest- Parameters:
listener- a listener for complete event- Returns:
- this request object
-
trailersSupplier
Description copied from interface:RequestProvides the trailers of this request.- Specified by:
trailersSupplierin interfaceRequest- Parameters:
trailers- the supplier of the trailers of this request- Returns:
- this request object
-
getBody
-
body
-
file
Description copied from interface:RequestShortcut method to specify a file as a content for this request, with the default content type of "application/octet-stream".- Specified by:
filein 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:RequestShortcut method to specify a file as a content for this request, with the given content type.- Specified by:
filein 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:
isFollowRedirectsin interfaceRequest- Returns:
- whether this request follows redirects
-
followRedirects
- Specified by:
followRedirectsin interfaceRequest- Parameters:
follow- whether this request follows redirects- Returns:
- this request object
-
getIdleTimeout
public long getIdleTimeout()- Specified by:
getIdleTimeoutin interfaceRequest- Returns:
- the idle timeout for this request, in milliseconds
-
idleTimeout
- Specified by:
idleTimeoutin interfaceRequest- Parameters:
timeout- the idle timeout for this requestunit- the idle timeout unit- Returns:
- this request object
-
getTimeout
public long getTimeout()- Specified by:
getTimeoutin interfaceRequest- Returns:
- the total timeout for this request, in milliseconds; zero or negative if the timeout is disabled
-
timeout
-
send
Description copied from interface:RequestSends 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.Listeneror a utility listener such asInputStreamResponseListener.The method returns when the
complete eventis fired.- Specified by:
sendin interfaceRequest- Returns:
- a
ContentResponsefor this request - Throws:
InterruptedException- if send thread is interruptedTimeoutException- if send times outExecutionException- if execution fails- See Also:
-
send
Description copied from interface:RequestSends 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.CompleteListenerbut 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_VALUEif there is no timeout. - See Also:
-
getResponseListeners
-
getPushHandler
-
getTrailersSupplier
- Specified by:
getTrailersSupplierin interfaceRequest- Returns:
- the supplier of the trailers of this request
-
abort
-
getAbortCause
- Specified by:
getAbortCausein interfaceRequest- Returns:
- the abort cause passed to
Request.abort(Throwable), or null if this request has not been aborted
-
toString
-