Available inall subroutines.

Determines whether the HTTP status matches or does not match any of the statuses in the supplied fmt string.

Returns true when the status matches any of the strings and returns false otherwise. If fmt is prefixed with !, returns true when the status does not match any of the strings and returns false if it does. Statuses in the string are separated by commas.

This function is not prefixed with the std. namespace.


The following snippet in vcl_fetch marks backend responses with status codes other than 200, 301, or 302 as not cacheable.

if (http_status_matches(beresp.status, "!200,301,302")) {
set beresp.cacheable = false;

Try it out

http_status_matches 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.

Replace origin errors with 'safe' responses

Detect specified response statuses from backends and instead serve a precomposed error page or error content generated at the edge.