15

I'm playing around with the HTTP range header (specs).

From what I understand I can set byte ranges of files ala

0-199/2000
200-499/2000
500-799/2000
etc

Question:
Say I only want to access certain ranges of a file, would it be possible to specify these ranges and then work with the "incomplete" data I received? I'm playing around with filtering a large log file, so I'm curious if something like this would work.

Thanks for inputs!

frequent
  • 27,643
  • 59
  • 181
  • 333
  • 1
    Seems to me like the perfect case to use that header. http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2 – Supericy Mar 04 '13 at 11:22
  • Yeah, I also think it was developed exactly for such cases. Haven't you tried if that works? – VisioN Mar 04 '13 at 11:28
  • As has already been mentioned, that's *exactly* what range requests are for. This is generally how media "streaming" is accomplished via HTTP. –  Mar 04 '13 at 13:46
  • yes. I'm thinking more into using this as a filter of a large file, similar to what is described [here](http://byterot.blogspot.fr/2012/07/range-header-asp-net-web-api-entity-pagination.html). Would be nice if it was possible to not only filter "from-to" like this. – frequent Mar 04 '13 at 13:48

1 Answers1

17

You are right, the link which you posted in the comment would be probably the best approach. As your question sounded interesting i tried it out. You probably did it also, but here is an snippet (for other, that may come looking)

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","data.dat",false);
xmlhttp.setRequestHeader("Range", "bytes=100-200");
xmlhttp.send();
console.info(xmlhttp); //--> returns only the partial content
// Tested on Win7 with chrome 46+

Watch-out: the web-server has to support this Request Header Range, for it to work.

winner_joiner
  • 12,173
  • 4
  • 36
  • 61
  • yeah. it's nice. I'm also playing around with it. Curious how to set custom-entities including related logic. – frequent Mar 06 '13 at 10:43
  • 1
    I assume Custom-entities would entail Serverside scripting/programming, and depence on webserver and programming language. here is a similar question/answer/approche/hint/... [link](http://stackoverflow.com/questions/1434647/using-the-http-range-header-with-a-range-specifier-other-than-bytes) :) . – winner_joiner Mar 06 '13 at 11:30