Package 

Class MobonResponse

  • All Implemented Interfaces:
    java.io.Closeable , java.lang.AutoCloseable

    
    public final class MobonResponse
     implements Closeable
                        

    An HTTP response. Instances of this class are not immutable: the response body is a one-shot value that may be consumed only once and then closed. All other properties are immutable.

    This class implements Closeable. Closing it simply closes its response body. See ResponseBody for an explanation and examples.

    • Method Detail

      • request

         MobonRequest request()

        The wire-level mobonRequest that initiated this HTTP response. This is not necessarily the samemobonRequest issued by the application:

        • It may be transformed by the HTTP client. For example, the client may copy headers like{@code Content-Length} from the mobonRequest body.
        • It may be the mobonRequest generated in response to an HTTP redirect or authenticationchallenge. In this case the mobonRequest URL may be different than the initial mobonRequest URL.
      • protocol

         Protocol protocol()

        Returns the HTTP protocol, such as HTTP_1_1 or HTTP_1_0.

      • code

         int code()

        Returns the HTTP status code.

      • isSuccessful

         boolean isSuccessful()

        Returns true if the code is in [200..300), which means the mobonRequest was successfully received,understood, and accepted.

      • handshake

         Handshake handshake()

        Returns the TLS handshake of the connection that carried this response, or null if the responsewas received without TLS.

      • peekBody

         ResponseBody peekBody(long byteCount)

        Peeks up to {@code byteCount} bytes from the response body and returns them as a new responsebody. If fewer than {@code byteCount} bytes are in the response body, the full response body isreturned. If more than {@code byteCount} bytes are in the response body, the returned valuewill be truncated to {@code byteCount} bytes.

        It is an error to call this method after the body has been consumed.

        Warning: this method loads the requested bytes into memory. Mostapplications should set a modest limit on {@code byteCount}, such as 1 MiB.

      • isRedirect

         boolean isRedirect()

        Returns true if this response redirects to another resource.

      • networkResponse

        @Nullable() MobonResponse networkResponse()

        Returns the raw response received from the network. Will be null if this response didn't usethe network, such as when the response is fully cached. The body of the returned responseshould not be read.

      • cacheResponse

        @Nullable() MobonResponse cacheResponse()

        Returns the raw response received from the cache. Will be null if this response didn't use thecache. For conditional get requests the cache response and network response may both benon-null. The body of the returned response should not be read.

      • priorResponse

        @Nullable() MobonResponse priorResponse()

        Returns the response for the HTTP redirect or authorization challenge that triggered thisresponse, or null if this response wasn't triggered by an automatic retry. The body of thereturned response should not be read because it has already been consumed by the redirectingclient.

      • challenges

         List<Challenge> challenges()

        Returns the authorization challenges appropriate for this response's code. If the response codeis 401 unauthorized, this returns the "WWW-Authenticate" challenges. If the response code is407 proxy unauthorized, this returns the "Proxy-Authenticate" challenges. Otherwise thisreturns an empty list of challenges.

      • cacheControl

         CacheControl cacheControl()

        Returns the cache control directives for this response. This is never null, even if thisresponse contains no {@code Cache-Control} header.

      • sentRequestAtMillis

         long sentRequestAtMillis()

        Returns a timestamp taken immediately before OkHttptransmitted the initiating mobonRequest over the network. If this response is being served from thecache then this is the timestamp of the original mobonRequest.

      • receivedResponseAtMillis

         long receivedResponseAtMillis()

        Returns a timestamp taken immediately after OkHttpreceived this response's headers from the network. If this response is being served from thecache then this is the timestamp of the original response.

      • close

         void close()

        Closes the response body. Equivalent to {@code body().close()}.

        It is an error to close a response that is not eligible for a body. This includes theresponses returned from cacheMobonResponse, networkMobonResponse, and .