HTTP Headers
Vary
The HTTP Vary
response header specifies which parts of the request message, aside from the method and URL, influence the content of the response in which it appears.
Adding a Vary
header ensures that responses are cached separately based on the headers listed within the Vary
field.
This is most commonly used to create a cache key when content negotiation is involved.
The same Vary
header value should be applied to all responses for a specific URL, including 304
Not Modified
responses and the default response.
Syntax
Specify either *
as a wildcard to match all headers or list one or more header names separated by commas:
Vary: *
Vary: <header-name>, <header-name>, <header-name>
Directives
Directives
* (wildcard)
Factors other than request headers influenced the generation of this response. This implies that the response is uncacheable.
<header-name>
A request header name that could have influenced the creation of this response.
How to Modify Header using Requestly
Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Vary header. This is especially useful for testing how your application handles caching and content negotiation during development or debugging. Steps to Modify the Vary Header:
- Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
- Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
- Add a new header modification:
- Under “Action”, select “Add” or “Override”.
- In the “Header Name” field, enter Vary.
- In the “Header Value” field, enter the header fields your server should vary on (e.g., Accept-Encoding, User-Agent).
- Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
- Save the rule.
Once set up, Requestly will inject the specified Vary header into all matching responses, helping you test how your server and clients behave with different cache variation strategies. You might need to modify the Vary header to control caching behavior and ensure that clients receive the correct version of a response based on certain headers like language or encoding. Adjusting this header helps prevent serving stale or incorrect content to users.
Table of Contents
- No headings found.