This is related to:How should I implement a COUNT verb in my RESTful web service? , Paging in a Rest Collectionand Using the HTTP Range Header with a range specifier other than bytes?

Actually I think the -1 rated anwser here is correct https://stackoverflow.com/a/1434701/1237617

Generally anwsers say that you can use custom units citing the sec 3.12

 range-unit = bytes-unit | other-range-unitbytes-unit = "bytes"other-range-unit = token

However when you read the HTTP spec please notice the production rules are thus:

 Content-Range = "Content-Range" ":" content-range-speccontent-range-spec = byte-content-range-specbyte-content-range-spec = bytes-unit SPbyte-range-resp-spec "/"( instance-length | "*" )

The header spec only references bytes-unit from sec 3.12, not range-units, so I think that actually it's against the spec to use custom units here.

Am I missing something or is the popular anwser wrong?

EDIT: Since this probbably isn't clear, the gist of my question is:rfc2616 sec14.16 only references bytes-unit. It never mentions range-unit, so range-unit production is not relevant for Content-Range, and thus only byte-units can be used.

I think this adresses my concerns best, although I needed some time to understand it (plus I wanted to make sure, that there is something wrong with the wording).

This reflects the fact that, apparently, the first set of grammar rules has been specifically made for parsing and the second one for producing HTTP requests

thanks to elgaton

4

Best Answer


The spec, as being revised, allows custom range units. See HTTPbis Part 5, Section 2.

If you read the HTTP/1.1 RFC, section 3.12, you will see that:

The only range unit defined by HTTP/1.1 is "bytes". HTTP/1.1 implementations MAY ignore ranges specified using other units.

So, the other-range-unit token has been introduced only to make servers more "liberal" when accepting. This reflects the fact that, apparently, the first set of grammar rules has been specifically made for parsing and the second one for producing HTTP requests, so that servers could accept even invalid requests (they will be simply ignored) and clients would use only the universally-accepted bytes unit.

Therefore, I personally recommend to:

  1. use only the bytes unit when acting as a client, and
  2. accept other units (discarding the Content-Range header if they are invalid) when acting as a server.

This is a purely personal opinion, but I think it is fairly consistent with how other HTTP extensions (custom methods or headers) are used. Here is how I read it: Yes I can use custom range units and no, I shouldn't submit a bug report when it gets ignored when passing through firewalls, web proxies, and other intermediaries. I conform to the HTTP spec when I'm sending it and they conform to HTTP when they ignore it. WebDAV uses HTTP extensions correctly, IMO, but rarely works over the Internet for exactly this reason. As I said, a personal opinion only.

Apparently it's OK to use custom units, because:

This reflects the fact that, apparently, the first set of grammarrules has been specifically made for parsing and the second one forproducing HTTP requests