Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use the HTTP range header to load partial files "on purpose"?

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!

like image 760
frequent Avatar asked Mar 04 '13 11:03

frequent


People also ask

What is Range HTTP header?

The Range HTTP request header indicates the part of a document that the server should return. Several parts can be requested with one Range header at once, and the server may send back these ranges in a multipart document. If the server sends back ranges, it uses the 206 Partial Content for the response.

What is partial HTTP request?

Partial request responsesA range request that is out of bounds will result in a 416 Requested Range Not Satisfiable status, meaning that none of the range values overlap the extent of the resource. For example, the first-byte-pos of every range might be greater than the resource length.


1 Answers

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, 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 this to work.

like image 108
winner_joiner Avatar answered Oct 05 '22 17:10

winner_joiner