Range
Range
GET /360_0388.jpg HTTP/1.1
Host: limit.qiufeng.com
Connection: keep-alive
...
Range: bytes=0-102399
HTTP/1.1 206 Partial Content
Server: openresty/1.13.6.2
Date: Sat, 19 Sep 2020 06:31:11 GMT
Content-Type: image/jpeg
Content-Length: 102400
....
Content-Range: bytes 0-102399/3670627
...(这里是文件流)
可以看到请求这里多出一个字段
Value | Description |
---|---|
206 | Partial Content |
416 | Range Not Satisfiable |
Range 格式
Range:(unit=first byte pos)-[last byte pos]
即Range: 单位(如bytes)= 开始字节位置-结束字节位置
。
我们来举个例子,假设我们开启了多线程下载,需要把一个
Range: bytes=0-1199 头1200 个字节Range: bytes=1200-2399 第二个1200 字节Range: bytes=2400-3599 第三个1200 字节Range: bytes=3600-5000 最后的1400 字节
服务器给出响应:
第
- Content-Length:1200
- Content-Range:bytes 0-1199/5000
第
- Content-Length:1200
- Content-Range:bytes 1200-2399/5000
第
- Content-Length:1200
- Content-Range:bytes 2400-3599/5000
第
- Content-Length:1400
- Content-Range:bytes 3600-5000/5000
如果每个请求都成功了,服务端返回的
Content-Range: bytes (unit first byte pos) - [last byte pos]/[entity length]
即Content-Range:字节 开始字节位置-结束字节位置/文件大小
。