Class Response
- All Implemented Interfaces:
Closeable,AutoCloseable
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbody()Returns a non-null value if this response was passed toCallback.onResponse(org.miaixz.bus.http.NewCall, org.miaixz.bus.http.Response)or returned fromNewCall.execute().Returns the cache control directives for this response.Returns the raw response received from the cache.Returns the RFC 7235 authorization challenges appropriate for this response's code.voidclose()Closes the response body.intcode()Returns the HTTP status code.Returns the TLS handshake of the connection that carried this response, or null if the response was received without TLS.headers()booleanReturns true if this response redirects to another resource.booleanReturns true if the code is in [200..300), which means the request was successfully received, understood, and accepted.message()Returns the HTTP status message.Returns the raw response received from the network.peekBody(long byteCount) Peeks up tobyteCountbytes from the response body and returns them as a new response body.Returns the response for the HTTP redirect or authorization challenge that triggered this response, or null if this response wasn't triggered by an automatic retry.org.miaixz.bus.core.net.Protocolprotocol()Returns the HTTP protocol, such asProtocol.HTTP_1_1orProtocol.HTTP_1_0.longReturns a timestamp taken immediately after Http received this response's headers from the network.request()The wire-level request that initiated this HTTP response.longReturns a timestamp taken immediately before Http transmitted the initiating request over the network.toString()trailers()Returns the trailers after the HTTP response, which may be empty.
-
Method Details
-
request
The wire-level request that initiated this HTTP response. This is not necessarily the same request issued by the application:- It may be transformed by the HTTP client. For example, the client may copy headers like
Content-Lengthfrom the request body. - It may be the request generated in response to an HTTP redirect or authentication challenge. In this case the request URL may be different than the initial request URL.
- It may be transformed by the HTTP client. For example, the client may copy headers like
-
protocol
public org.miaixz.bus.core.net.Protocol protocol()Returns the HTTP protocol, such asProtocol.HTTP_1_1orProtocol.HTTP_1_0. -
code
public int code()Returns the HTTP status code. -
isSuccessful
public boolean isSuccessful()Returns true if the code is in [200..300), which means the request was successfully received, understood, and accepted. -
message
Returns the HTTP status message. -
handshake
Returns the TLS handshake of the connection that carried this response, or null if the response was received without TLS. -
headers
-
header
-
header
-
headers
-
trailers
Returns the trailers after the HTTP response, which may be empty. It is an error to call this before the entire HTTP response body has been consumed.- Throws:
IOException
-
peekBody
Peeks up tobyteCountbytes from the response body and returns them as a new response body. If fewer thanbyteCountbytes are in the response body, the full response body is returned. If more thanbyteCountbytes are in the response body, the returned value will be truncated tobyteCountbytes.It is an error to call this method after the body has been consumed. Warning: this method loads the requested bytes into memory. Most applications should set a modest limit on
byteCount, such as 1 MiB.- Throws:
IOException
-
body
Returns a non-null value if this response was passed toCallback.onResponse(org.miaixz.bus.http.NewCall, org.miaixz.bus.http.Response)or returned fromNewCall.execute(). Response bodies must be closed and may be consumed only once.This always returns null on responses returned from
cacheResponse,networkResponse, andpriorResponse(). -
newBuilder
-
isRedirect
public boolean isRedirect()Returns true if this response redirects to another resource. -
networkResponse
Returns the raw response received from the network. Will be null if this response didn't use the network, such as when the response is fully cached. The body of the returned response should not be read. -
cacheResponse
Returns the raw response received from the cache. Will be null if this response didn't use the cache. For conditional get requests the cache response and network response may both be non-null. The body of the returned response should not be read. -
priorResponse
Returns the response for the HTTP redirect or authorization challenge that triggered this response, or null if this response wasn't triggered by an automatic retry. The body of the returned response should not be read because it has already been consumed by the redirecting client. -
challenges
Returns the RFC 7235 authorization challenges appropriate for this response's code. If the response code is 401 unauthorized, this returns the "WWW-Authenticate" challenges. If the response code is 407 proxy unauthorized, this returns the "Proxy-Authenticate" challenges. Otherwise this returns an empty list of challenges.If a challenge uses the
token68variant instead of auth params, there is exactly one auth param in the challenge at keynull. Invalid headers and challenges are ignored. No semantic validation is done, for example thatBasicauth must have arealmauth param, this is up to the caller that interprets these challenges. -
cacheControl
Returns the cache control directives for this response. This is never null, even if this response contains noCache-Controlheader. -
sentRequestAtMillis
public long sentRequestAtMillis()Returns a timestamp taken immediately before Http transmitted the initiating request over the network. If this response is being served from the cache then this is the timestamp of the original request. -
receivedResponseAtMillis
public long receivedResponseAtMillis()Returns a timestamp taken immediately after Http received this response's headers from the network. If this response is being served from the cache then this is the timestamp of the original response. -
close
public void close()Closes the response body. Equivalent tobody().close().It is an error to close a response that is not eligible for a body. This includes the responses returned from
cacheResponse,networkResponse, andpriorResponse().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
toString
-