We've been making changes to how we organize and display our docs. Our work isn't done but we'd love your feedback.

accept.media_lookup()

Selects the best match from a string in the format of an Accept header's value in the listed media types, using the algorithm described in Section 5.3.2 of RFC 7231.

This function takes the following parameters:

  1. a colon-separated list of media types available for the resource,
  2. a fallback return value,
  3. a colon-separated list of media types, each corresponding to a media type pattern,
  4. a string representing an Accept header's value.

The matching procedure is case insensitive, matched media types are returned verbatim as supplied to the matching function. Values of the first three arguments can not contain variables. Duplicate media types among the first three arguments are not allowed.

Format

STRING
accept.media_lookup(STRING requested_media_types, STRING default, STRING range_defaults, STRING accept_header)

Examples

1
2
3
4
5
6
7
8
9
# 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);