Available in all subroutines.

Provides a means to access subfields from a header like Cache-Control, Cookie, and Edge-Control or individual parameters from the 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 Set-Cookie field.

This functionality is also achievable by using the : accessor within a variable name. When the subfield is a valueless token (like "private" in the case of Cache-Control: max-age=1200, private), an empty string is returned. The : accessor also works for retrieving variables in a cookie.

This function is not prefixed with the std. namespace.


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";
if (subfield(beresp.http.Set-Cookie, "httponly", ";")) {
set req.http.value-of-foo = subfield(req.url.qs, "foo", "&");

Try it out

subfield is used in the following solution recipes, which show real world use cases. Click RUN to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Time-limited URL tokens

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.

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.