Content-Range working in Safari but not in Chrome

依然范特西╮ 提交于 2019-12-10 11:40:04

问题


I'm streaming audio files from a Node.js Express server with Content-Range headers plus no caching headers. This works ok in latest Safari instead, but it does not in Chrome.

While when streaming the full audio file with HTTP 200, my headers were

{ 'Content-Length': 4724126,
  'Content-Type': 'audio/mpeg',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
  'Access-Control-Allow-Headers': 'POST, GET, OPTIONS',
  Expires: 0,
  Pragma: 'no-cache',
  'Cache-Control': 'no-cache, no-store, must-revalidate' }

and it works on both Chrome and Safari <audio> tag.

When streaming partial contents with HTTP 206 the headers were

{ 'Content-Length': 4724126,
  'Content-Type': 'audio/mpeg',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
  'Access-Control-Allow-Headers': 'POST, GET, OPTIONS',
  Expires: 0,
  Pragma: 'no-cache',
  'Cache-Control': 'no-cache, no-store, must-revalidate',
  'Accept-Ranges': 'bytes',
  'Content-Range': 'bytes 120515-240260/4724126' }

This led to an error of the Chrome page where the <audio> or <video> tag was.

Even the embedded media tag created by Chrome when using the streaming url right in the browser it is not working, and led to this

The audio file is served reading a local file and creating a file read stream via Node.js the createReadStream api:

var file = fs.createReadStream(path, {start: range[0], end: range[1]});

I have posted the code for the server here.

[UPDATE]

It turns not that Chrome is more strict about Range and Content-Range requests/responses. So any Content-Range response must have a Range previous request. The typical case is scrubbing a player bar to the second S. The api will send a "Range" request, the server will respond with a "Content-Range" header. In my case I was sending a Content-Range response over an ordinary request without "Range". Safari works because is more street-html complaint i.e. it does not strictly require a "Range" request before a "Content-Range" response. So, I removed the "Content-Range" header from my response, and not it works. End of the story (!).

To follow up this issue I have posted in Chromium net-dev forum too in Chrome bad Range header: Range: bytes=0-

来源:https://stackoverflow.com/questions/53259737/content-range-working-in-safari-but-not-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!