最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can I use the HTTP range header to load partial files "on purpose"? - Stack Overflow

programmeradmin1浏览0评论

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!

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!

Share Improve this question asked Mar 4, 2013 at 11:15 frequentfrequent 28.5k61 gold badges187 silver badges336 bronze badges 4
  • 1 Seems to me like the perfect case to use that header. w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2 – Supericy Commented Mar 4, 2013 at 11:22
  • Yeah, I also think it was developed exactly for such cases. Haven't you tried if that works? – VisioN Commented Mar 4, 2013 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. – user895378 Commented Mar 4, 2013 at 13:46
  • yes. I'm thinking more into using this as a filter of a large file, similar to what is described here. Would be nice if it was possible to not only filter "from-to" like this. – frequent Commented Mar 4, 2013 at 13:48
Add a comment  | 

1 Answer 1

Reset to default 18

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.

发布评论

评论列表(0)

  1. 暂无评论