http Pragma 的有效值是多少
http header pragma
的有效值是多少。我知道 no-cache
是其中之一,但我想要启用缓存,所以我应该设置它。我做了一些谷歌搜索,我得到的只是大多数客户忽略了这一点,但没有关于它接受的其他值的信息。
What are the valid values for http header pragma
. I know no-cache
is one but i wnat to enable caching so what should i set it. I did some googleing and all that i got was most clients ignore this but no info on other values it accepts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
令人惊讶的是,默认情况下只定义了一个参数,即 no-cache,并且根据 RFC,HTTP 中不会定义新的 Pragma 指令。
参考:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14。 html#sec14.32
此外,您将需要使用 Cache-Control 标头来管理缓存行为而不是 Pragma 指令,后者似乎仍然只是为了支持旧版 HTTP/1.0。
参考:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14。 html#sec14.9
奖励:http://www.mnot.net/cache_docs/
Surprisingly there is only one parameter defined by default, which is no-cache and no new Pragma directives will be defined in HTTP as per RFC.
ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32
Moreover, you will need to use the Cache-Control header for managing the caching behaviors rather than the Pragma directive which seems to be still included only to support the legacy HTTP/1.0.
ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
Bonus: http://www.mnot.net/cache_docs/
您可能正在寻找 Cache-Control,这个在 HTTP/1.1 中受支持,并且定义了比 编译指示。
You're probably looking for Cache-Control, this is supported in HTTP/1.1 and defines more states than Pragma.
更多信息,可能会帮助一些对缓存不太感兴趣、对 http 标头更感兴趣的人。即原始问题的字面解释“http header pragma 的有效值是什么”?
接受的答案(https://stackoverflow.com/a/7376516/3246928)中的参考是 RFC http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32。它将 snytax 定义为:
这暗示任何“token=value”对都是可接受的(值是可选的)。规范继续说
我猜这也意味着涵盖“扩展编译指示”部分,但我希望它们在这里更加明确。
这个标头似乎不是专门为缓存创建的; RFC 中的描述说:
因此,理论上,您可以在此处添加内容,并且它们可以工作。然而,尽管进行了大量搜索,我还没有找到任何对此处使用过的任何其他值的引用。它实际上是 http/1 中死气沉沉且令人尴尬的部分。
看起来正常的做法是:
仅使用带有 no-cache 标志的 pragma。这是任何人都应该使用的唯一值。 (当然,您还应该使用缓存控制标头以使缓存按预期运行)。
如果您想将一些特殊信息放入http标头中 - 即如果您想“包含可能适用于请求/响应链上任何接收者的特定于实现的指令”,则创建一个自定义http标头。例如,谷歌和亚马逊就是这样做的:
http://docs.aws.amazon.com/AmazonS3/latest/ dev/UsingMetadata.html 和
https://cloud.google.com/storage/docs/reference-headers
请注意 http 标头的命名约定。 “x-”前缀已弃用
通过 https://www.rfc-editor.org/rfc/rfc6648,但是每个人似乎都用它
无论如何。
Some more information, that might help some people that are less interested in caching, and more interested in http headers in general. i.e the literal interpretation of the original question, "what are the valid values for the http header pragma"?
The reference in the accepted answer (https://stackoverflow.com/a/7376516/3246928) is the RFC http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32. It defines the snytax as:
This implies that any 'token=value' pair is acceptable (with the value being optional). The spec goes on to say
and I would guess this is also meant to cover the "extension-pragma" part, but I wish they had been more unambiguous here.
This header does not seem to be specifically created for caching; the description in the RFC says:
So, in theory, you could add things here, and they could work. However, despite much searching, I have not found any reference to any other values ever being used here. It is effectively a dead and embarrassing part of http/1.
It seems like the normal thing to do is:
Only use pragma with the no-cache flag. This is the only value anyone should ever use. (And of course you should also use the cache-control header for your caching to behave as expected).
If you want to put some special information into a http header - i.e. If you want to "include implementation-specific directives that might apply to any recipient along the request/response chain", then create a custom http header. Google and Amazon, for example, do this:
http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html and
https://cloud.google.com/storage/docs/reference-headers
Note the naming convention on the http header. The "x-" prefix is deprecated
by https://www.rfc-editor.org/rfc/rfc6648, but everyone seems to use it
anyway.