简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM