常见的“accept-ranges”标头是字节。但是,对我来说,可能有许多其他类型的范围。
我正在编写一个采用日期范围的API资源。在accept-ranges标头中指定日期并期望来自客户端的范围标题是否有意义?
答案 0 :(得分:4)
我一直在研究与Accept-Ranges& amp;范围标题似乎是传递分页数据的理想选择。
HTTP1.1规范声明:
range-unit = bytes-unit | 其他范围单元强>
这表明您可以使用自己的单位类型,但接着说
HTTP / 1.1定义的唯一范围单位是字节。 HTTP / 1.1实现可以忽略使用其他单元指定的范围。
虽然支持的唯一范围单位是字节,但该语句确实强调HTTP 1.1可以(不应该)忽略其他单位的范围 - 所以也许它取决于你?
但是,HTTP头包含与消息体相关的数据而不是消息体所代表的数据,因此只支持字节单元才有意义,因为无论代表什么资源,都可以将字节范围应用于消息体。而日期范围是基于上下文的范围,仅适用于某些情况。
正如您在问题中提到的,实现日期范围的方法是在对该URL的HEAD或OPTIONS请求的响应中提供自定义 Accept-Ranges 标头,然后传递< em>范围标头,包含对同一网址的任何GET请求
我认为由开发人员决定是否以这种方式使用它,但对我而言,这个方形钉的孔太圆了!传递查询字符串中的值。
<强>参考:强>
3.12 Range Units
HTTP/1.1 allows a client to request that only part (a range of) the response entity be included within the response. HTTP/1.1 uses range units in the Range (section 14.35) and Content-Range (section 14.16) header fields. An entity can be broken down into subranges according to various structural units.
range-unit = bytes-unit | *other-range-unit*
bytes-unit = "bytes"
other-range-unit = token
The only range unit defined by HTTP/1.1 is "bytes". HTTP/1.1 implementations MAY ignore ranges specified using other units.
HTTP/1.1 has been designed to allow implementations of applications that do not depend on knowledge of ranges.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.12