views:

1170

answers:

3

The core question is about the use of the HTTP Headers, including Range, If-Range, Accept-Ranges and a user defined range specifier.

Here is a manufactured example to help illustrate my question. Assume I have a Web 2.0 style application that displays some sort of human readable documents. These documents are editorially broken up into pages (similar to articles you see on news websites). For this example, assume:

  • There is a document titled "HTTP Range Question" is broken up into three pages.
  • The shell page (/document/shell/http-range-question) knows the meta information about the document, including the number of pages.
  • The first readable page of the document is loaded during the page onload event via an ajax GET and inserted onto the page.
  • A UI control that looks like [ 1 2 3 All ] is at the bottom of the page, and clicking on a number will display that readable page (also loaded via ajax), and clicking "All" will display the entire document. Assume these URLS for the 1, 2, 3 and All use cases:
    • /document/content/http-range-question?page=1
    • /document/content/http-range-question?page=2
    • /document/content/http-range-question?page=3
    • /document/content/http-range-question

Now to the question. Can I use the HTTP Range headers instead part of the URL (e.g. a querystring parameter)? Maybe something like this on the GET /document/content/http-range-question request:

Range: page=1

It looks like the spec only defines byte ranges as allowable, so even if I made my ajax calls work with my browser and server code, anything in the middle could break the contract (e.g. a caching proxy server).

Range: bytes=0-499

Any opinions or real world examples of custom range specifiers?

Update: I did find a similar question about the Range header (Paging in a Rest Collection) where they mention that Dojo's JsonRestStore uses a custom Range header value.

Range: items=0-24
+1  A: 

It sounds like you want to change the HTTP spec just to remove a querystring parameter. In order to do this you'd have to modify code on both the client to send the modified header and the server to read from the "Range" header instead of the querystring.

The end result is that this will probably work, but you're breaking all of the standards and existing tools to do so.

David
I see it more as trying to adhere to the spirit of the spec in that one URL can get the whole content or, using a header defined in the spec, can get logical parts of the content (but just not segmented by bytes). However, it's entirely possible this is a bad idea even if I could get it to work.
Kevin Hakanson
A: 

The Range can accepts bytes only.

You can add a custom HTTP Request header instead with the values that you want to pass, and most proxies will forward all headers to the backend. I do not see any issue in using a custom HTTP Header, do add a comment if you feel that there is an issue in using a custom header versus using the Range Header.

Many HTTP based systems that I have seen use the "Cookie" header to send name/value pairs.

This would be an easier approach rather than attempting to use a predefined HTTP Header that has other meanings in the HTTP protocol. I completely agree with David's point.

Thiyagaraj
I worry about browser and proxy caching if I use a custom header to modify the scope of my request as it might not be honored. Mabye I can use a Vary header on the response to prevent any wrong caching.
Kevin Hakanson
You can use the "Cookie" header if possible - though, it could interfere with other cookies if not done properly..
Thiyagaraj
+1  A: 

HTTP Range is typically used for recovering interrupted downloads without starting from the beginning.

What you're trying to do would be better handled by OAI-ORE, which allows you to define relationships between multiple documents. (alternative formats, components of the whole, etc)

Unfortunately, it's a relatively new metadata format, and I don't know of any web browsers that ship with native support.

Joe