大文件下载中断了,怎么接着下?服务器怎么回应 Range?哪些写法会得到 416?流式响应能不能支持断点续传?这篇用真实的 curl 续传和 13 种 Range 写法验证。
无 Range: 200 | Accept-Ranges = bytes | Content-Length = 10240 Range: bytes=0-99 → 206 | Content-Range: bytes 0-99/10240 | 收到 100 字节 | 内容与文件对应片段一致:True Range: bytes=100-199 → 206 | Content-Range: bytes 100-199/10240 | 收到 100 字节 | 内容与文件对应片段一致:True Range: bytes=-50 → 206 | Content-Range: bytes 10190-10239/10240 | 收到 50 字节 Range: bytes=10000- → 206 | Content-Range: bytes 10000-10239/10240 | 收到 240 字节 Range: bytes=0-0 → 206 | Content-Range: bytes 0-0/10240 | 收到 1 字节 | 内容与文件对应片段一致:True Range: bytes=10239-10239 → 206 | Content-Range: bytes 10239-10239/10240 | 收到 1 字节 | 内容与文件对应片段一致:True Range: bytes=0-999999 → 206 | Content-Range: bytes 0-10239/10240 | 收到 10240 字节 | 内容与文件对应片段一致:True Range: bytes=10240- → 416 | Content-Range: bytes */10240 | 收到 177 字节 Range: bytes=20000-30000 → 416 | Content-Range: bytes */10240 | 收到 177 字节 Range: bytes=5-2 → 416 | Content-Range: bytes */10240 | 收到 177 字节 Range: bytes=0-9,20-29 → 416 | Content-Range: bytes */10240 | 收到 177 字节 Range: items=0-5 → 416 | Content-Range: bytes */10240 | 收到 177 字节 Range: bytes=abc → 416 | Content-Range: bytes */10240 | 收到 177 字节
上一篇:Session Cookie 的数据结构;下一篇:Content Negotiation;send_file 的更多细节:send_file() 与 send_from_directory()。
Range: bytes=0-9 + If-Range = 当前 ETag → 206 收到 10 字节 Range: bytes=0-9 + If-Range = 过期的 ETag → 200 收到 10240 字节 Range: bytes=0-9 + If-Range = 当前 Last-Modified → 206 收到 10 字节
第一次(只取 0-2999)文件大小: 3000 curl -C - 续传: 206 本次传输 7240 字节 | 最终文件大小 10240 SHA-256 与原文件相同: True
/gen Range: bytes=0-99 → 200 | Accept-Ranges = None | 收到 1000 字节 /custom Range: bytes=100-199 → 206 | Content-Range = bytes 100-199/10240 | 收到 100 字节 | 内容正确: True /custom Range: bytes=99999- → 416 | Content-Range = bytes */10240
HEAD + Range: bytes=0-9 → 206 | Content-Range = bytes 0-9/10240 | Content-Length = 10 | 正文 0