Available in all subroutines.
Selects the best match from a string in the format of an
value in the listed media types using the algorithm described in Section 5.3.2
of RFC 7231.
This function takes the following parameters:
- a colon-separated list of media types available for the resource,
- a fallback return value,
- a colon-separated list of media types, each corresponding to a media type pattern,
- a string representing an
The matching procedure is case insensitive and matched media types are returned verbatim as supplied to the matching function. Values of the first three arguments cannot contain variables. Duplicate media types are not allowed among the first three arguments.
# We wish `image/jpeg` to return `image/jpeg`.# We wish `image/png` to return `image/png`.# We wish `image/*` to return `image/tiff`.# We wish `text/*` to return `text/html`.# We wish `*/*` to return `text/plain`.set beresp.http.media = accept.media_lookup("image/jpeg:image/png","text/plain","image/tiff:text/html",req.http.Accept);
Try it out
accept.media_lookup 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.
Improve cache performance by normalizing requests. Filter and reorder query params, convert to lowercase, filter headers, and more.
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.