T
- the response body typepublic abstract class HttpResponse<T> extends Object
HttpRequest
. A HttpResponse
is
available when the response status code and headers have been received, and
typically after the response body has also been received. This depends on
the response body handler provided when sending the request. In all cases,
the response body handler is invoked before the body is read. This gives
applications an opportunity to decide how to handle the body.
Methods are provided in this class for accessing the response headers, and response body.
Response handlers and processors
Response bodies are handled at two levels. Application code supplies a response
handler (HttpResponse.BodyHandler
) which may examine the response status code
and headers, and which then returns a HttpResponse.BodyProcessor
to actually read
(or discard) the body and convert it into some useful Java object type. The handler
can return one of the pre-defined processor types, or a custom processor, or
if the body is to be discarded, it can call BodyProcessor.discard()
and return a processor which discards the response body.
Static implementations of both handlers and processors are provided in
BodyHandler
and BodyProcessor
respectively.
In all cases, the handler functions provided are convenience implementations
which ignore the supplied status code and
headers and return the relevant pre-defined BodyProcessor
.
See HttpResponse.BodyHandler
for example usage.
Modifier and Type | Class | Description |
---|---|---|
static interface |
HttpResponse.BodyHandler<T> |
A handler for response bodies.
|
static interface |
HttpResponse.BodyProcessor<T> |
A processor for response bodies.
|
static interface |
HttpResponse.MultiProcessor<U,T> |
A response processor for a HTTP/2 multi response.
|
Modifier | Constructor | Description |
---|---|---|
protected |
HttpResponse() |
Creates an HttpResponse.
|
Modifier and Type | Method | Description |
---|---|---|
abstract T |
body() |
Returns the body.
|
abstract HttpRequest |
finalRequest() |
Returns the final
HttpRequest that was sent on the wire for the
exchange ( may, or may not, be the same as the initial request ). |
abstract HttpHeaders |
headers() |
Returns the received response headers.
|
abstract HttpRequest |
request() |
Returns the initial
HttpRequest that initiated the exchange. |
abstract SSLParameters |
sslParameters() |
Returns the
SSLParameters in effect for this
response. |
abstract int |
statusCode() |
Returns the status code for this response.
|
abstract CompletableFuture<HttpHeaders> |
trailers() |
Returns the received response trailers, if there are any, when they
become available.
|
abstract URI |
uri() |
Returns the
URI that the response was received from. |
abstract HttpClient.Version |
version() |
Returns the HTTP protocol version that was used for this response.
|
public abstract int statusCode()
public abstract HttpRequest request()
HttpRequest
that initiated the exchange.public abstract HttpRequest finalRequest()
HttpRequest
that was sent on the wire for the
exchange ( may, or may not, be the same as the initial request ).public abstract HttpHeaders headers()
public abstract CompletableFuture<HttpHeaders> trailers()
HttpResponse
itself is available. In such cases, the
returned CompletableFuture
will be already completed.public abstract T body()
T
, the returned body may
represent the body after it was read (such as byte[]
, or
String
, or Path
) or it may represent an object with
which the body is read, such as an InputStream
.public abstract SSLParameters sslParameters()
SSLParameters
in effect for this
response. Returns null
if this is not a HTTPS response.public abstract URI uri()
URI
that the response was received from. This may be
different from the request URI
if redirection occurred.public abstract HttpClient.Version version()
Submit a bug or feature
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 2015, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-Debian+0-9b153-2