【问题标题】:HTTP Request headers and cachingHTTP 请求标头和缓存
【发布时间】:2016-06-29 20:26:07
【问题描述】:

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

以这个 HTTP 请求/响应为例:

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 标头的第二个请求有效?例如:

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

那么在第一个请求后的一个小时内,代理应该请求一个新的响应,因为请求标头不同,还是应该使用第一个请求的缓存响应,忽略标头?

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

【问题讨论】:

    标签: google-chrome http caching microsoft-edge


    【解决方案1】:

    除非更改的标头出现在the (optional) Vary response header 提供的列表中,否则您应该使用缓存版本。

    例如,响应包含

     Vary: accept-encoding, accept-language
    

    表示源服务器可能使用了请求的
    Accept-Encoding 和 Accept-Language 字段(或缺少)为
    选择此响应的内容时的决定因素。

    【讨论】:

      猜你喜欢
      • 2018-03-02
      • 1970-01-01
      • 2017-10-07
      • 2015-07-13
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2021-11-29
      • 1970-01-01
      相关资源
      最近更新 更多