HTTP范围标头 [英] HTTP Range header

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

问题描述

我正在阅读 http://www.w3.org /Protocols/rfc2616/rfc2616-sec14.html#sec14.35
并试图找出如何继续下载文件。

I was reading http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 and trying to figure out how to continue a file download.

例如,假设一个文件的长度为100个字节,并且我有100个字节。但是,我不知道预期的文件大小应该是多少,所以我要求这个文件并指定一个Range头部,如下所示:

For example, suppose a file is of length 100 bytes and I have all the 100 bytes. However, I don't know what the expected file size should be, so I ask for the file and specify a Range header that looks like this:

Range: bytes=100-

这是一个有效的范围请求吗?

Is this a valid Range request?

推荐答案

这是一个语法上有效的请求,但不是可满足的请求。如果您仔细查看该部分,您会看到:

It's a syntactically valid request, but not a satisfiable request. If you look further in that section you see:


如果语法上有效的字节范围集包含至少一个字节范围spec其第一字节位置小于实体主体的当前长度,或者至少一个后缀字节位置规范具有非零后缀长度,则字节范围集合是可满足的。否则,字节范围集是不可满足的。 如果字节范围集合不可满足,服务器应该返回状态为416(请求的范围不可满足)的响应。否则,服务器应该返回状态为206(部分内容)的响应,其中包含实体主体的可满足范围。

If a syntactically valid byte-range-set includes at least one byte- range-spec whose first-byte-pos is less than the current length of the entity-body, or at least one suffix-byte-range-spec with a non- zero suffix-length, then the byte-range-set is satisfiable. Otherwise, the byte-range-set is unsatisfiable. If the byte-range-set is unsatisfiable, the server SHOULD return a response with a status of 416 (Requested range not satisfiable). Otherwise, the server SHOULD return a response with a status of 206 (Partial Content) containing the satisfiable ranges of the entity-body.

所以我认为在你的例子中,服务器应该返回一个416,因为它不是该文件的有效字节范围。

So I think in your example, the server should return a 416 since it's not a valid byte range for that file.

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

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