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

端点续传(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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值