HTTP状态码206:什么时候应该使用? [英] HTTP Status Code 206: When should it be used?
问题描述
206状态代码(w3。 org)表示响应具有 Range
标题的请求的部分结果。
The 206 status code (w3.org) indicates a partial result in response to a request with a Range
header.
所以清楚如果要求的文件是例如1024字节长,范围
标头是 bytes = 0-512
然后状态代码 206部分内容
。 (假设服务器能够返回内容)
So "clearly" if the requested document is e.g. 1024 bytes long, and the Range
header is bytes=0-512
then a status code of 206 Partial Content
should be returned. (Assuming that the server is able to return the content)
但是如果范围
是<$ c $怎么办? c> bytes = 0-2000 ?
应 200 OK
或 206部分内容
可以退货吗?
在我看来,这在规范中没有明确定义 - 或者我可能没有在正确的位置阅读?
BUT what if the Range
is bytes=0-2000
?
Should 200 OK
or 206 Partial Content
be returned?
It seems to me that this isn't clearly defined in the specification -- or maybe I'm not reading the right place?
我为什么关心?
我问,因为 Varnish Cache 似乎总是返回 206 Partial Content
,而 Facebook Open Graph调试器似乎期望 200 OK
。 [ 1 ] [ 2 ]
Why do I care?
I ask because the Varnish Cache seems to always return 206 Partial Content
, whereas the Facebook Open Graph debugger seems to expect 200 OK
. [1] [2]
示例:对Varnish的GET请求
(我收到完整的文档,然后返回 206 Partial Content
)
Example: GET request to Varnish
(I receive the full document, and yet 206 Partial Content
is returned)
> curl --dump-header - -H 'Range: bytes=0-7000' https://www.varnish-cache.org/sites/all/themes/varnish_d7/logo.png
HTTP/1.1 206 Partial Content
Server: nginx/1.1.19
Date: Mon, 14 Apr 2014 22:43:31 GMT
Content-Type: image/png
Content-Length: 2884
Connection: keep-alive
Last-Modified: Thu, 15 Dec 2011 12:30:46 GMT
Accept-Ranges: bytes
X-Varnish: 1979866667
Age: 0
Via: 1.1 varnish
Content-Range: bytes 0-2883/2884
进一步参考w3: http://www.w3 .org / Protocols / rfc2616 / rfc2616-sec14.html#sec14.35
推荐答案
没关系。这两个回复都是有效的。
It doesn't matter. Both replies are valid.
(另请注意,当前的规范现在是 http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p5-range-26.html ,将发布为RFC很快)
(also note that the current specification is now http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p5-range-26.html, to be published as RFC soon)
这篇关于HTTP状态码206:什么时候应该使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!