Movatterモバイル変換


[0]ホーム

URL:


  1. Home
  2. Reference documentation
  3. VCL reference
  4. Subroutines

vcl_recv

The built-invcl_recv subroutine is executed when a client request is received by Fastly or as a result of arestart.

Typically, the recv state is used for tasks such as:

The default return path fromvcl_recv forGET requests islookup, which will trigger thevcl_hash subroutine, perform a cache key calculation and look up the resulting address in the cache, ultimately triggering thevcl_hit,vcl_miss orvcl_pass subroutines as appropriate. It's also possible toreturn(pass), which will still perform a cache key calculation, but will always transition fromvcl_hash tovcl_pass. Returningupgrade will terminate the VCL execution and Fastly will maintain the connection as a persistentWebSockets tunnel.

Changes made to thereq object invcl_recv will affect the calculation of the cache key, if the changed properties are included inobj.hash byvcl_hash.

The exception statementsrestart anderror may both be used inrecv.

Method specific behavior

At the end ofvcl_recv, the default behavior is dependent on the method of the inbound request:

  • GET,HEAD, andPURGE requests will trigger alookup, while all other methods will cause apass. This behavior is in theboilerplate VCL and is overridable by using custom VCL in your service.
  • If the return state islookup, methods other thanGET andPOST will be converted toGET on the backend request (bereq) and any request body will be dropped. This behavior is part of the Fastly platform and is not overridable.

HINT: With the default boilerplate VCL, the rules above will result in the conversion of aHEAD request into aGET to your origin server, allowing Fastly to populate the resource into our cache, but the response to the client will correctly exclude the content body, since the client requested only the HEAD.

State transitions

  • Inbound request
  • restart
vcl_recv
  • return(lookup)hash
  • return(pass)hash
  • errorhash
  • restartrecv
  • return(upgrade)

To see this subroutine in the context of the full VCL flow, seeour guide about Fastly VCL.

Example

The code exampleUse microservices to divide up a domain is a good example of thevcl_recv subroutine in use:

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


[8]ページ先頭

©2009-2025 Movatter.jp