Hi @jkebinger
Each subroutine (e.g. vcl_fetch
, vcl_deliver
, vcl_log
etc) has access to different types of objects.
One of these objects is the ‘response’ object.
Access to the response is allowed in subroutines such as vcl_fetch
, vcl_deliver
and vcl_log
but the way it is accessed changes slightly between subroutines.
To reference the response object from vcl_fetch
you use beresp
.
In the documentation for vcl_fetch
you’ll see, under the “Tokens available in this subroutine” section, the token beresp.http.{NAME}
.
For example, when you want to set a header on the origin response (so the content gets stored in the cache with the header modification), you would use something like the following inside of vcl_fetch
:
set beresp.http.MyHeaderName = "example";
If you instead wanted to set a header on the origin response (but not have the content stored in the cache with the modified header), you would set the header inside of vcl_deliver
instead. This is because by the time vcl_deliver
is executed (after vcl_fetch
) the content has already been stored in the cache. So the response object you’re modifying is sent to the client, but the header modification isn’t persisted into the cache.
But critically, setting a header on the response in vcl_deliver
(and this is the same for vcl_log
) requires you to switch from beresp
to resp
:
set resp.http.MyHeaderName = "example";
In the documentation for vcl_log
(same for vcl_deliver
) you’ll see, under the “Tokens available in this subroutine” section, the token resp.http.{NAME}
.
NOTE: The reason for the difference in name (e.g. beresp
vs resp
) is to try and make it clearer what it is you’re modifying. In the case of beresp
(i.e. “backend response”) you’re modifying the origin response, and any modifications to the origin response will be persisted into the cache. Where as resp
is the final response that is sent to the client and so changes there are not persisted into cache. It’s a subtle but important distinction.
Hope this helps.