Manipulate the HTTP Vary header.
npm install varyimport { vary, append, format, parse } from "vary";Adds the given header field to the Vary response header of res. This can be a string of a single field, a string of a valid Vary header, or an array of multiple fields.
This will append the header if not already listed, otherwise leaves it listed in the current location.
// Append "Origin" to the Vary header of the response
vary(res, "Origin");Returns the updated Vary header string after adding field to header. Pass a single field name, a comma-separated string of field names, or an array of field names.
Field names are compared case-insensitively. Each new name is appended and existing names stay in place. If either argument contains a wildcard *, the result is "*". Invalid field names in field throw a TypeError.
// Get header string appending "Origin" to "Accept, User-Agent"
append("Accept, User-Agent", "Origin");Splits a Vary header into an array of strings.
parse("Accept-Encoding, Origin"); // ["Accept-Encoding", "Origin"]Validates and joins field names with , , preserving all fields as-is. Invalid field names throw a TypeError.
format(["Accept-Encoding", "Origin", "origin"]); // "Accept-Encoding, Origin, origin"// In a request handler that serves content based on the User-Agent header
vary(res, "User-Agent");