Support for the Edge-Control header

VCL provides the building blocks to access information inside the Edge-Control response header field from the origin. We support this by honoring cache-maxage from Edge-Control as the time to live (TTL) of the object on the Fastly edge, and honoring downstream-ttl from Edge-Control as the TTL to be sent down from the Fastly edge to the end user's browser.

In order to incorporate this Edge-Control header support, use VCL Snippets to update your vcl_fetch:

  1. Log in to the Fastly web interface.
  2. From the All services page, select the appropriate service. You can use the search box to search by ID, name, or domain.
  3. Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.
  4. Click the VCL Snippets link. The VCL Snippets page appears.
  5. Click Create Snippet. The Create a VCL snippet page appears.

    vcl snippet window

  6. In the Name field, enter an appropriate name (e.g., Edge-Control Header parse_time_delta).
  7. From the Type controls, select within subroutine.
  8. From the Select subroutine menu, select fetch (vcl_fetch).
  9. In the VCL field, add the following conditions:

    1
    2
    3
    
    if (parse_time_delta(beresp.http.Edge-Control:cache-maxage) >= 0) {
      set beresp.ttl = parse_time_delta(beresp.http.Edge-Control:cache-maxage);
    }
    
  10. Click Create to create the snippet.
  11. Click Create Snippet. The Create a VCL snippet page appears.

    vcl snippet window

  12. In the Name field, enter an appropriate name (e.g., Edge-Control Header downstream-ttl handling).
  13. From the Type controls, select within subroutine.
  14. From the Select subroutine menu, select deliver (vcl_deliver).
  15. In the VCL field, add the following conditions:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    if (fastly.ff.visits_this_service == 0) {
      if (resp.http.Edge-Control:downstream-ttl == "-1") {
        set resp.http.Cache-Control =  "no-cache, no-store, must-revalidate, proxy-revalidate, private, max-age=0, s-maxage=0";
        set resp.http.Expires = "1970-01-01 00:00:00";
      } else if (parse_time_delta(resp.http.Edge-Control:downstream-ttl) >= 0) {
        set resp.http.Cache-Control:max-age = parse_time_delta(resp.http.Edge-Control:downstream-ttl);
      }
      unset resp.http.Edge-Control;
    }
    
  16. Click Create to create the snippet.
  17. Click the Activate button to deploy your configuration changes.

The subfield function parses the Edge-Control field for subfields, and the parse_time_delta function converts time values like "7m" into a number of seconds. You can then use that number of seconds to populate beresp.ttl (the TTL of the object on the Fastly edge) or you can use it to construct a Cache-Control header field for downstream. The parse_time_delta function will return -1 if the subfield is not well-formed as a time value, or if it is entirely absent. The above snippet honors cache-maxage and downstream-ttl from Edge-Control if present and usable.

Back to Top