开发者

What are the Valid values for http Pragma

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 value开发者_高级运维s it accepts.


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/


You're probably looking for Cache-Control, this is supported in HTTP/1.1 and defines more states than Pragma.


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:

Pragma = "Pragma" ":" 1#pragma-directive

pragma-directive = "no-cache" | extension-pragma

extension-pragma = token [ "=" ( token | quoted-string ) ]

This implies that any 'token=value' pair is acceptable (with the value being optional). The spec goes on to say

No new Pragma directives will be defined in HTTP.

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:

The Pragma general-header field is used to include implementation- specific directives that might apply to any recipient along the request/response chain

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜