Class CombineResponse

java.lang.Object
org.frontcache.include.combine.CombineResponse

public class CombineResponse extends Object
The origin's half of the combine contract: build and write the response envelope. See docs/archive/combine-reduce-proposal.md section 6. Parts must be added in the order the members arrived - parts[i] answers fc-part-i. writeTo(HttpServletResponse) is what sets the x-frontcache-combine header, which is the only signal the edge has that the origin understood the request at all; an origin that writes the JSON by hand and forgets that header will be treated as not implementing combining.
  • Constructor Details

    • CombineResponse

      public CombineResponse()
  • Method Details

    • add

      public CombineResponse add(String body)
      A part with no echo, no explicit status and no headers - i.e. an uncacheable 200 fragment.
    • add

      public CombineResponse add(String q, String body, Map<String, List<String>> headers)
      A part with cache directives. Keys are the x-frontcache-component-* names in FCHeaders.
    • add

      public CombineResponse add(String q, int status, Map<String, List<String>> headers, String body)
    • addComponent

      public CombineResponse addComponent(String q, String body, String maxAge, String tags)
      A cacheable part, spelled the way the <fc:component> tag spells it.
      Parameters:
      q - echo of this member's query string, or null to omit it
      body - the fragment
      maxAge - x-frontcache-component-maxage, e.g. "10d"; null means not cacheable
      tags - x-frontcache-component-tags, e.g. "coin|coin-42"; null to omit
    • addError

      public CombineResponse addError(String q, int status)
      A member the origin could not render. Not cached by the edge; that member falls back.
    • size

      public int size()
    • getEnvelope

      public CombineEnvelope getEnvelope()
    • toJson

      public String toJson() throws IOException
      Throws:
      IOException
    • writeTo

      public void writeTo(jakarta.servlet.http.HttpServletResponse response) throws IOException
      Writes the envelope: content type, the x-frontcache-combine support signal, an explicit content length, and the JSON body. The length is set explicitly because the body is already fully in hand - letting the container fall back to chunked encoding for a response whose size is known costs the edge a read-until-EOF where it could have read a known number of bytes.
      Throws:
      IOException