LOG IN SIGN UP
Documentation

Isolating header values without regular expressions

  Last updated May 23, 2018

Fastly supports the ability to extract header subfield values without regular expressions in a human-readable way. "Headers subfields" are headers with a body syntax style similar to value1=123value123; testValue=asdf_true; staff_user=true; or max-age=0, surrogate-control=3600 These headers include Cookie, Set-Cookie, Cache-Control, or a custom header. Fastly allows you to isolate these key values with the following syntax:

req.http.Header-Name:key-name

For example, if a Set-Cookie response from origin was value1=123value123; testValue=asdf_true; staff_user=true;, you could isolate the staff_user value using this logic:

beresp.http.Set-Cookie:staff_user

You can add this logic using VCL Snippets or using a custom header.

Using VCL Snippets

To execute this logic based on the value of staff_user within req.http.Cookie using a VCL Snippet, you would:

  1. Log in to the Fastly web interface and click the Configure link.
  2. From the service menu, select the appropriate service.
  3. Click the Configuration button and then select Clone active. 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, type an appropriate name (e.g., Staff User Cookie).
  7. From the Type controls, select within subroutine.
  8. From the Select subroutine menu, select recv (vcl_recv).
  9. In the VCL field, add the following condition:

    # in vcl_recv
    if (req.http.Cookie:staff_user ~ "true") {
      # some logic goes here
      return(pass);
    }
    
  10. Click Create to create the snippet.
  11. Click the Activate button to deploy your configuration changes.

Using a custom header

You can isolate the value of staff_user from Cookie to the header req.http.staff_user by creating a custom header with the following settings:

the header window showing a custom header without regular expressions

Fill out the Create a header fields as follows:

This will send the staff_user header in every inbound request.


Back to Top