http 206 Range -- 端点续传(resumed download) -- POST/PUT/DELETE

来源:互联网 发布:张靓颖冯轲sm 知乎 编辑:程序博客网 时间:2024/05/17 00:11
端点续传(resumed download):
请求:
Range: bytes=16-
响应:
HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Range: bytes 16-14385736/14385737
Content-Length: 14385721
Request -- Response
* no Range -- 如果是小文件,发送整个文件;否则发送206 偏移从0开始。
* "Range:" -- 同上。
* "Range: bytes=0-" -- 发送206,如果文件不大,把Range填满。
* "Range: bytes=x-y" -- 标准格式,按要求发送。
修改[2]prepare_local_file()后,
对于有Range的请求,发200,wget和curl都能收,只要确保Content-Length和实际发的内容长度一样,貌似做法似乎不标准。

如果请求没有包含Range,你发了206,但是curl并不会再发起一个请求来接收剩下的!

测试:

wget -d -c http://127.0.0.1:8080/bigfile.dat -O bigfile.dat
立即中断,多跑几次。
加上--header='Range: bytes=0-'测试不行,原因见[1]

用curl才行:
curl -v --range 16-31  http://127.0.0.1:8080/config.h -o config.h

telnet也可:
telnet 127.0.0.1 8080
GET /config.h HTTP/1.1
Range: bytes=300-400
<Enter>

<Enter>


实现:

open(name, flag, mode);
1. name 不能是这样的"a/b", 要写成"./a/b",否则产生2 -- 找不到文件的错误。
2. 首次写没有问题,再次open产生13 -- EACCESS错误,发现权限是0016。
mode must be specified when O_CREAT is in the flags, and is ignored otherwise.
open(name, O_CREAT|O_WRONLY|O_TRUNC, 0644);

curl -v --upload-file myfile.txt http://localhost:8080/upload/ #PUT上传
curl -v http://localhost:8080/upload/ #获取列表
curl -v --request DELETE http://localhost:8080/upload/myfile.txt #删除
curl --data-binary @datafile http://localhost:8080/post.cgi #POST上传
curl --head http://localhost:8080/ #只要header信息,不要传body数据


[1] http://superuser.com/questions/377142/using-wget-and-manually-assing-range-header

[2] https://github.com/DeYangLiu/ffmpeg-streaming/commit/d3b62cf640a3bc4a387c9286a7a47719151c6ec5

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
http://blog.codingnow.com/2010/06/detect_utf-8_gbk.html

0 0
原创粉丝点击