哪些HTTP状态代码可以缓存? [英] Which HTTP status codes are cacheable?
问题描述
如标题所述,哪些HTTP状态代码可以作为浏览器缓存?我做了一个快速搜索,没有找到权威的答案。
As stated in the title, which HTTP status codes are acceptable to cache as a browser? I did a quick search and did not find an authoritative answer.
最初我认为它可能只是 200
确定回复,但我找不到任何证据支持这个想法。
Originally I thought it may only be 200
OK responses, but I couldn't find any evidence to support that thought.
推荐答案
简短回答
根据 RFC 7231 ,HTTP / 1.1协议的内容和语义的当前参考,定义了以下HTTP状态代码as cacheable ,除非方法定义另有说明或显式缓存控件:
Short answer
According to the RFC 7231, the current reference for content and semantics of the HTTP/1.1 protocol, the following HTTP status codes are defined as cacheable unless otherwise indicated by the method definition or explicit cache controls:
-
200
确定 -
203
非权威信息 -
204
无内容 -
206
部分内容 -
300
多种选择 -
301
永久移动 -
404
未找到 -
405
Method Not Not允许 -
410
消失 -
414
URI太长 -
501
未实施
200
OK203
Non-Authoritative Information204
No Content206
Partial Content300
Multiple Choices301
Moved Permanently404
Not Found405
Method Not Allowed410
Gone414
URI Too Long501
Not Implemented
RFC 7231 声明了以下关于默认情况下可缓存的HTTP状态代码:
The RFC 7231 states the following regarding the HTTP status codes that are cacheable by default:
[...]状态代码的响应默认情况下定义为可缓存
(例如, 200
, 203
, 204
, 206
, 300
, 301
, 404
, 405
, 410
, 414
,除非到期的缓存重用 501
in
此规范) tools.ietf.org/html/rfc7231#section-4.3rel =noreferrer>方法定义或
显式缓存控件;默认情况下,所有其他状态代码都不是
可缓存的。 [...]
[...] Responses with status codes that are defined as cacheable by default
(e.g., 200
, 203
, 204
, 206
, 300
, 301
, 404
, 405
, 410
, 414
, and 501
in
this specification) can be reused by a cache with heuristic
expiration unless otherwise indicated by the method definition or
explicit cache controls; all other status codes are not
cacheable by default. [...]
一旦HTTP状态代码是可扩展的,收件人必须注意缓存具有无法识别的状态代码的响应:
Once the HTTP status codes are extensible, recipient must note cache a response with an unrecognized status code:
status-code元素是一个三位整数代码,给出了尝试理解的
结果并且满足请求。
The status-code element is a three-digit integer code giving the result of the attempt to understand and satisfy the request.
HTTP状态代码是可扩展的。
不需要HTTP客户端理解所有已注册状态代码的含义,尽管这种
理解显然是可取的。但是,客户必须
了解任何状态代码的类别,如第一个
数字所示,并将无法识别的状态代码视为等于
x00
该类的状态代码,但
收件人不得缓存具有无法识别的状态代码的响应。 [...]
HTTP status codes are extensible. HTTP clients are not required to
understand the meaning of all registered status codes, though such
understanding is obviously desirable. However, a client MUST
understand the class of any status code, as indicated by the first
digit, and treat an unrecognized status code as being equivalent to
the x00
status code of that class, with the exception that a
recipient MUST NOT cache a response with an unrecognized status code. [...]
缓存还取决于HTTP方法:
The cache also depends on the HTTP method:
请求方法可以定义为可缓存,以指示允许存储
对它们的响应未来重用。通常,
不依赖于当前或权威响应的安全方法被定义为
cacheable;此规范将 GET
, HEAD
和 POST
定义为
可缓存,尽管绝大多数缓存
实现仅支持 GET
和 HEAD
。
Request methods can be defined as "cacheable" to indicate that
responses to them are allowed to be stored for future reuse. In general, safe methods that
do not depend on a current or authoritative response are defined as
cacheable; this specification defines GET
, HEAD
, and POST
as
cacheable, although the overwhelming majority of cache
implementations only support GET
and HEAD
.
关于 POST
方法,有一个重要的细节:
Regarding the POST
method, there's an important detail:
[...]对 POST
请求的回复只有在它们包括
明确的新鲜度信息 [...]
[...] Responses to POST
requests are only cacheable when they include
explicit freshness information [...]
有关详细信息,请查看每种方法的定义。
For more details, check the definition of each method.
- RFC 7234 :HTTP / 1.1协议中的缓存参考
- 检查哪些浏览器存储在其缓存中
- RFC 7234: Reference for caching in the HTTP/1.1 protocol
- Check what browsers store in their cache
这篇关于哪些HTTP状态代码可以缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!