Giovanni Lovato
Giovanni Lovato

Reputation: 2273

HTTP Request headers and caching

How should an HTTP Agent make decisions about using cached response when a request has the same path but different headers?

Take for example this HTTP request/response:

GET /resource HTTP/1.1
Host: example.org
X-Filter: foo=bar

HTTP/1.1 200 OK
Cache-Control: max-age=3600
Content-Type: application/json
Content-Length: 13

{"foo":"bar"}

Should the agent consider the response valid for a second request with a different X-Filter header? For example:

GET /resource HTTP/1.1
Host: example.org
X-Filter: foo=baz

then within an hour from the first request, should the agent request a fresh response since the request header differs, or should use the cached response from the first request, ignoring the header?

I'm asking this because I noticed that Google Chrome makes a new request, Microsoft Edge instead use the cached response.

Upvotes: 4

Views: 1085

Answers (1)

Quentin
Quentin

Reputation: 944301

You should use the cached version unless changed header appears in the list provided by the (optional) Vary response header.

For example, a response that contains

 Vary: accept-encoding, accept-language

indicates that the origin server might have used the request's
Accept-Encoding and Accept-Language fields (or lack thereof) as
determining factors while choosing the content for this response.

Upvotes: 4

Related Questions