HTTP请求标头和缓存 [英] HTTP Request headers and caching

查看:139
本文介绍了HTTP请求标头和缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

例如,这个HTTP请求/响应:

  GET /资源HTTP / 1.1 
主机: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 /资源HTTP / 1.1 
主机:example.org
X-Filter: foo = baz

然后在距离第一个请求一小时内,代理请求一个新的响应,请求标头不同,或者应该使用来自第一个请求的缓存响应,忽略标头?



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

解决方案

您应该使用缓存版本,除非更改标题出现在(可选) Vary 响应头


例如,一个包含

Vary:接受编码,接受语言

表示源服务器可能已经使用了请求的
接受编码和接受语言字段(或缺少)作为

决定因素,同时选择此响应的内容。



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.

这篇关于HTTP请求标头和缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆