Available inall subroutines.
Tests a given
condition, and returns
value_when_true when the condition is TRUE, and
value_when_false when the condition is FALSE.
You can use
if() as a construct to make simple, conditional expressions
set req.http.foo-status = if(req.http.foo, "present", "absent");
Try it out
if is used in the following code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.
Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.
Apply HTTP basic auth to private endpoints
Store username/password list in an edge dictionary, authorize user at the edge, reject requests that don't have correct credentials.
Log the IP version (IPv4/IPv6)
Identify which type of IP address was used by the client connecting to your Fastly service.