我正在尝试将一个播客添加到 itunes 中,该播客正在处理字节范围请求。我可以通过curl
音频文件来确认这一点:
curl -H "Range: bytes=50-100" --head http://media.site.org/podcasts/upload/2012/08/15/audio-081512.mp3
HTTP/1.1 200 OK
Server: nginx/1.2.0
Date: Wed, 15 Aug 2012 22:28:40 GMT
Content-Type: audio/mpeg
Content-Length: 51
Connection: keep-alive
X-Powered-By: Express
Status: 206 Partial Content
Accept-Ranges: bytes
Content-Range: bytes 50-100/1441605
Access-Control-Allow-Origin: *
但是,当我尝试将 feed 页面的 URL 输入 iTunes 时,出现以下错误:
"There is a problem with your feed. Your episodes are hosted on a server which doesn't support byte-range requests. Enable byte-range requests and try your submission again."
音频文件托管在与提要文件不同的服务器上,并且由节点服务器提供服务...但我不明白为什么只要响应 header 正确,这就很重要。
我还有一些其他播客从同一服务器提供,这些播客是在 iTunes 开始需要字节范围支持之前添加的,并且它们仍然可以正常工作(在任何平台上,包括 iPhone,这表明字节范围请求确实有效)。
最佳答案
如果响应 header 的 HTTP 状态为 200
,那么即使服务器正在接受字节范围请求,iTunes 也会拒绝播客。我所要做的就是强制 206 Partial Response
header 。在 Node 中,它看起来像这样(CoffeeScript):
res.writeHead 206, headers
headers
是包含字节范围请求的所有正确 header 的哈希,例如:
headers:
"Accept-Ranges": "bytes"
"Content-Range": "bytes #{start}-#{end}/#{length}
start
和end
变量是通过解析 Range
获取的请求 header ,以及 length
是音频文件的实际大小。我还投入了"Cache-Control": "no-cache"
为了更好的衡量。
关于http - iTunes 范围请求;播客被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11978335/