Identify backend in response headers


1 comment

  • Philipp Schulte

    Hi Damien,

    I was running into the same problem! Not all VCL variables are available in all VCL subroutines.

    Any hints about which variables are within scope for vcl_deliver that can provide info. about which backend responded? Or is this only possible to set on the backend itself (so that provides the header, rather than inserting it retrospectively)?

    Fastly provides three values that allow you to see and track origin information:

    • => The name of the backend that was used for this request
    • beresp.backend.port => The port of the backend that was used for this request
    • beresp.backend.ip => The IP of the backend that was used for this request

    The problem is that all these VCL variables are only available in vcl_fetch. That's the reason why you received an error because you have tried to reference directly in vcl_deliver.

    The solution is to define your custom header in vcl_fetch:

    ``` sub vcl_fetch {


    set beresp.http.X-Origin-Name =;


    } ```

    You have three possibilities to configure your custom header in vcl_fetch:

    1. Header
    2. VCL Snippet
    3. Custom VCL

    The output of has the following format:

    < X-Origin-Name: <the_fastly_service_id--F_<the_vcl_backend_name>

    The values captured in a header within vcl_fetch will flow to vcl_deliver. For example, there will exist a resp.http.X-Origin-Name header in vcl_deliver that corresponds to in vcl_fetch. By default, the response header will be included in the response output. You can wrap the set expressions in an if statement to control the behavior.

    For security purposes, I recommend adding the custom header to your logging string and removing it from the response headers. You can reference your custom header in your logging string by wrapping it in %{<header_name>}o i.e. %{http.X-Origin-Name}o. Please use the unset statement in vcl_deliver if you want to strip the header from the response:

    ``` sub vcl_deliver {


    unset resp.http.X-Origin-Name;


    } ```

    You can strip your custom header in vcl_deliver via Header, VCL Snippet, or Custom VCL.

    Fastly provides great documentation on this topic. Please review their docs on how to track your origin's name, IP, and port for further information especially if you are shielding.

    I could also really use a nice reference for what variables are available (and their scope) in general if anyone has any nice guides/links that summarise it?

    The only reference about Fastly VCL variables I know of is the Fastly's VCL Extensions documentation. However, these docs don't explain if a variable is read-only and/or read-write and in what VCL subroutines the variable can be used.

    Comment actions Permalink

Please sign in to leave a comment.