Class Response


  • public final class Response
    extends Object
    An HTTP response. Instances of this class are not immutable: the response body is a one-shot value that may be consumed only once. All other properties are immutable.
    • Method Detail

      • request

        public Request 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-Length from 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.
      • 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

        public String message()
        Returns the HTTP status message or null if it is unknown.
      • handshake

        public Handshake handshake()
        Returns the TLS handshake of the connection that carried this response, or null if the response was received without TLS.
      • headers

        public Headers headers()
      • isRedirect

        public boolean isRedirect()
        Returns true if this response redirects to another resource.
      • networkResponse

        public Response 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

        public Response 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

        public Response 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

        public List<Challenge> challenges()
        Returns the 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.
      • cacheControl

        public CacheControl cacheControl()
        Returns the cache control directives for this response. This is never null, even if this response contains no Cache-Control header.
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.