Class Response

    • Constructor Detail

      • Response

        protected Response​(byte[] responseBytes,
                           Map<String,​List<String>> headers,
                           int responseCode,
                           int requestId,
                           int responseTime,
                           net.toddm.cache.LoggingProvider loggingProvider)
    • Method Detail

      • getResponseBytes

        public byte[] getResponseBytes()
        Returns the response body of this response as raw bytes, or null if there is no response body.
      • getResponseBody

        public String getResponseBody()
        Returns the response body of this response as a String, or null if there is no response body or the response body bytes can not be interpreted as a UTF-8 string.
      • getResponseCode

        public Integer getResponseCode()
        Returns the HTTP Status Code for this response, or null if there isn't one.
      • getResponseTimeMilliseconds

        public int getResponseTimeMilliseconds()
        Returns the total amount of time, in milliseconds, that it took to get this response from the time it started processing.
      • isFromCache

        public boolean isFromCache()
        Returns true if this Response was served from cache. Returns false if this Response was received via a network request.
      • isSuccessful

        public boolean isSuccessful()
        Returns true if this Response instance has an HTTP response code that we consider to indicate "success". Currently this either 200 or 201.
      • getRequestId

        public Integer getRequestId()
        Returns the unique ID of the Request that generated this Response.
      • getHeaders

        public Map<String,​List<String>> getHeaders()
        The HTTP header values from the response.
      • getInstanceCreationTime

        protected long getInstanceCreationTime()
        Returns the epoch timestamp in milliseconds of when this instance of Response was created.
      • getContentEncoding

        public static String getContentEncoding​(Map<String,​List<String>> headers)
        Returns the value for the 'Content-Encoding' header from the given header collection, or NULL if no value can be resolved.
      • getLocationFromHeaders

        public URI getLocationFromHeaders​(Request request)
        If we are able to resolve a Location value form the headers of this Response instance and parse that value to a URI then the Location value is returned, otherwise NULL is returned. This method resolves any relative redirects to absolute redirects.

        Parameters:
        request - The Request that resulted in this Response. This is used for rewriting relative URLs if needed.
        Returns:
        The URI that the HTTP response headers indicates should be redirected to.
      • getRetryAfter

        public Long getRetryAfter()
        If we are able to resolve a Retry-After value form the headers of this Response instance then the Retry-After value is returned, otherwise NULL is returned. The Retry-After value returned is in seconds. This method does support 'HTTP-date' values for Retry-After, but they are interpreted in relation to the current time and a simple value in seconds is still returned.
      • shouldNotCacheDueToNoCacheDirective

        public boolean shouldNotCacheDueToNoCacheDirective()
        If the Cache-Control headers of this Response instance contain the "no-cache" directive true is returned, otherwise false is returned.
      • getTtlFromHeaders

        public Long getTtlFromHeaders()
        If we are able to resolve a TTL value form the Cache-Control headers ("max-age") of this Response instance then the TTL value is returned, otherwise NULL is returned. The TTL value returned is in milliseconds.
      • getMaxStaleFromHeaders

        public Long getMaxStaleFromHeaders()
        If we are able to resolve a "max-stale" value form the Cache-Control headers of this Response instance then the value is returned, otherwise NULL is returned. The "max-stale" value returned is in milliseconds.
      • getETagFromHeaders

        public String getETagFromHeaders()
        If we are able to resolve an ETag value form the headers of this Response instance then the ETag value is returned, otherwise NULL is returned.