subfield

STRINGsubfieldSTRINGsubjectSTRINGfieldnameSTRINGseparator_character

Available inall subroutines.

Provides a means to access subfields from an HTTP header like Cache-Control or Cookie, or individual parameters from a string of key=value pairs, such as req.url.qs (the current request's query string).

The optional separator character parameter defaults to ,. It can be any one-character constant. For example, ; is a useful separator for extracting parameters from a Cookie field and & is a useful separator for extracting query string parameters from a URL.

It's also possible to read and write header subfields using the : accessor operator. See HTTP headers for details.

This function always matches case insensitively.

Examples

if (subfield(beresp.http.Cache-Control, "private")) {
return (pass);
}
set beresp.ttl = beresp.http.Cache-Control:max-age;
set beresp.http.Cache-Control:max-age = "1200";
set req.http.value-of-foo = subfield(req.url.qs, "foo", "&");
set req.http.value-of-bar = subfield(req.http.Cookie, "bar", ";");

Try it out

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

Create self-destructing URLs for time-limited access

Make URLs expire after a configurable period.

Send HTTP Basic Auth in request to origin

Convert a password sent by the client in the querystring into a Authorization header to your origin server.