XMLHtt prequest 206部分内容

问题描述:

我想从发布在JavaScript中XMLHtt prequest对象的部分内容请求。我加载来自服务器的大型二进制文件,我宁愿从服务器类似于如何HTML5视频的处理流式处理。

I would like to issue a partial content request from an XMLHttpRequest object in javascript. I'm loading a large binary file from the server, and I'd rather stream it from the server similar to how html5 video is handled.

我可以用setRequestHeader设置Range头。网络检查员在Chrome表明Range头设置成功。然而,Accept-Encoding头被设置为gzip压缩,放气,和Chrome不会让我设置的头(来自W3C标准)。

I can use setRequestHeader to set the Range header. The Network inspector in Chrome shows that the Range header is set successfully. However, the Accept-Encoding header is set to "gzip,deflate", and Chrome will not let me set that header (from W3C standards).

有没有什么办法来强制服务器从XMLHtt prequest对象206部分内容只能从JavaScript应对?

Is there any way to force the server to respond with a 206 partial content from the XMLHttpRequest object only from javascript?

我想我想通了,为什么206请求没有工作。用gzip COM pression允许的范围内,头部被忽略,如果传出的数据可以用gzip压缩。

I think I figured out why the 206 request wasn't working. With gzip compression enabled, the range header gets ignored if the outgoing data can be gzipped.

我请求文件是一个大的二进制文件,nginx的PTED具有MIMETYPE应用程序/八位字节流跨$ P $。这是一个被gzip压缩的MIME类型之一。如果我改名有一个.png格式文件类型的文件时,图像/ PNG MIMETYPE不是gzip压缩,因此范围请求正常工作。

The file I was requesting was a large binary file, which nginx interpreted as having mimetype application/octet-stream. This is one of the mimetypes that gets gzipped. If I renamed the file to have a .png filetype, the image/png mimetype is not gzipped, and hence the range request works correctly.

这也是为什么设置了Accept-Encoding头,卷曲身份还允许范围请求做工精细。但是,我无法从XHR改变这一头。

This is also why setting the Accept-Encoding header with curl to identity also allows the range request to work fine. However, I cannot change that header from an XHR.

解决方法:更改服务器上的MIMETYPE表

Solution: Change the mimetype table on the server!