简体   繁体   English

HTTP请求标头和缓存

[英]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? 当请求具有相同路径但不同的标头时,HTTP代理应该如何决定使用缓存响应?

Take for example this HTTP request/response: 以此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"}

Should the agent consider the response valid for a second request with a different X-Filter header? 代理是否应该将响应视为对具有不同X-Filter标头的第二个请求有效? 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. 我问这个是因为我发现Google Chrome会发出新请求,而Microsoft Edge则会使用缓存响应。

You should use the cached version unless changed header appears in the list provided by the (optional) Vary response header . 您应该使用缓存版本,除非更改的标题出现在(可选) Vary响应标头提供的列表中。

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 Accept-Encoding和Accept-Language字段(或缺少)字段为
determining factors while choosing the content for this response. 在选择此响应的内容时确定因素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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