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).
  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:

    if (parse_time_delta(subfield(beresp.http.Edge-Control, "downstream-ttl")) >= 0) {
      set beresp.http.Cache-Control = "max-age=" parse_time_delta(subfield(beresp.http.Edge-Control, "downstream-ttl"));
    if (parse_time_delta(subfield(beresp.http.Edge-Control, "cache-maxage")) >= 0) {
      set beresp.ttl = parse_time_delta(subfield(beresp.http.Edge-Control, "cache-maxage"));
  10. Click Create to create the snippet.
  11. 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