Class WebResponse

java.lang.Object
org.frontcache.core.WebResponse
All Implemented Interfaces:
Serializable

public class WebResponse extends Object implements Serializable
Container for web response. Usually it's text response for GET method.
See Also:
  • Constructor Details

    • WebResponse

      public WebResponse()
    • WebResponse

      public WebResponse(String url)
      some responses has no body (e.g. response for redirect) maxAgeStr = null so, content is not subject to cache (maxAge = 0/no_cache)
      Parameters:
      url -
    • WebResponse

      public WebResponse(String url, byte[] content)
      maxAgeStr = null so, content is not subject to cache (maxAge = 0/no_cache)
      Parameters:
      url -
      content -
    • WebResponse

      public WebResponse(String url, byte[] content, String maxAgeStr, String refreshType)
  • Method Details

    • getStatusCode

      public int getStatusCode()
    • setStatusCode

      public void setStatusCode(int statusCode)
    • getUrl

      public String getUrl()
    • setUrl

      public void setUrl(String url)
    • getHeaders

      public Map<String, List<String>> getHeaders()
    • getHeader

      public String getHeader(String name)
    • isText

      public boolean isText()
    • setHeaders

      public void setHeaders(Map<String, List<String>> headers)
      Parameters:
      headers -
    • getTags

      public Set<String> getTags()
      Returns:
    • setTags

      public void setTags(Set<String> tags)
      Parameters:
      tags -
    • addTags

      public void addTags(Collection<String> tags)
      Parameters:
      tags -
    • getContent

      public byte[] getContent()
      Returns:
    • setContent

      public void setContent(byte[] content)
      Parameters:
      content -
    • isCacheable

      public boolean isCacheable()
      Check if response is cacheable
      Returns:
    • getContentLenth

      public long getContentLenth()
      content length in bytes
      Returns:
    • addHeader

      public void addHeader(String name, String value)
    • copy

      public WebResponse copy()
      A shallow copy: the content byte[] is SHARED, not cloned. That is deliberate and is what keeps a cache hit from duplicating the whole page - the copy exists so that putToCache's in-place header strip, and the response headers a caller adds, do not reach the instance held in the cache. Two things here were wrong rather than merely slow, and both are fixed:
      • the header map came back as a plain HashMap. Every map built by FCUtils.revertHeaders is a TreeMap(String.CASE_INSENSITIVE_ORDER), because header names are case-insensitive (RFC 7230) and intermediaries re-case them - so copying into a HashMap silently made the copy case-SENSITIVE, and a re-cased Content-Type stopped resolving on it. The comparator is preserved now;
      • it routed through new WebResponse(url, content), whose constructor calls setExpireTime(null) - a trim, four endsWith checks and an Integer.parseInt in FCUtils.maxAgeStr2Int(String) - to populate an expireTimeMap that the very next line overwrote. This runs on every cache hit.
    • getExpireTimeMillis

      public long getExpireTimeMillis()
      Effective expiration timestamp (epoch millis) of this response across all client types. Used for time-based purging of stale entries. An entry that is still serveable to bots until T1 and to guests until T2 is fully expired only after max(T1, T2), so the latest expiration wins.
      Returns:
      CACHE_FOREVER (-1) if the response never expires; NO_CACHE (0) if it is not cacheable for any client type; otherwise the latest expiration timestamp among client types.
    • getExpireTimeMap

      public Map<String,Long> getExpireTimeMap()
    • setExpireTimeMap

      public void setExpireTimeMap(Map<String,Long> expireTimeMap)
    • getRefreshType

      public String getRefreshType()
    • setRefreshType

      public void setRefreshType(String refreshType)
    • getCacheLevel

      public String getCacheLevel()
    • setCacheLevel

      public void setCacheLevel(String cacheLevel)