HTTP 请求 headers 和缓存

HTTP Request headers and caching

当请求具有相同的路径但 headers 不同时,HTTP 代理应如何决定使用缓存的响应?

以这个 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"}

代理是否应该考虑响应对具有不同 X-Filter header 的第二个请求有效?例如:

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

然后在第一个请求的一个小时内,由于请求 header 不同,代理应该请求新的响应,还是应该使用第一个请求的缓存响应,忽略 header?

我问这个是因为我注意到 Google Chrome 提出了一个新请求,而 Microsoft Edge 使用缓存的响应。

您应该使用缓存版本,除非 header 出现在 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.