vcl_pass
The built-invcl_pass subroutine is executed whenpass is returned by thevcl_recv,vcl_miss, orvcl_hit subroutines.
The subroutinesvcl_pass andvcl_miss are very similar in nature. They both run immediately prior to a backend fetch, usually on afetch node. In preparation for making a request to the backend, a copy of the client request is created, and is available asbereq. This backend request object is writable, and any changes made to it do not affect the state of the client request, nor the cache address in which the response may be stored. This is therefore a good opportunity to remove any headers that you do not wish to send to the backend or to add authentication data required by the backend.
Key use cases:
- Preparing request headers for a specific origin/backend.
- Adding authentication requirements when the origin is a private bucket at AWS S3, GCS or similar.
- Unsetting request headers that are being used internally in VCL and are not required at origin.
Thevcl_pass subroutine shouldreturn(pass) to start the backend fetch.error may be used invcl_pass but it is not possible torestart the request from here.
Ifvcl_pass is invoked due toreturn(pass) invcl_recv, it will execute on thedelivery node. If it is triggered byreturn(pass) invcl_hit orvcl_miss, it may instead run on afetch node as a result ofclustering.
Using a 'prefetch' custom subroutine
Since it is common forvcl_miss andvcl_pass to perform broadly the same tasks, it is often useful to create a custom subroutine and invoke it from both places:
sub miss_pass {# Common logic goes here}sub vcl_pass {#FASTLY pass call miss_pass;}sub vcl_miss {#FASTLY miss call miss_pass;}State transitions
To see this subroutine in the context of the full VCL flow, seeour guide about Fastly VCL.
Tokens available in this subroutine
The following limited-scope VCL functions and variables are available for use in this subroutine (those inbold are availableonly in this subroutine, those available in *all* subroutines are not listed):