免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3254 | 回复: 5
打印 上一主题 下一主题

[C] axel源码中看到的content-length比实际的少一个字节,为啥子? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-03-23 10:46 |只看该作者 |倒序浏览
本帖最后由 lylesong 于 2014-03-23 10:46 编辑

用axel看到的长度比 用httpfox看到的content-length 少一个字节,

比如这个链接,

http://qianqian.baidu.com/download/BaiduMusic-12345630.exe


httpfox看到的是 Content-Length        7421120

而 axel中看到的却是  Content-Length: 7421119

但是从实际下载来看,文件又没有损坏,这个是为啥子啊?

论坛徽章:
0
2 [报告]
发表于 2014-03-23 12:04 |只看该作者
哦,请求头里面加了一句

Range: bytes=1-


所以网站返回来的数据就是
  1. Content-Range: bytes 1-7421119/7421120
复制代码
对于Range: 这个参数不咋个理解,从1开始,咋个还变少了。

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
3 [报告]
发表于 2014-03-23 13:58 |只看该作者
怪怪的。。

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
4 [报告]
发表于 2014-03-23 18:46 |只看该作者
断点续传诶。。。因为从1开始所以就不需要第1个字节而只需要后续部分了啊。。。

论坛徽章:
0
5 [报告]
发表于 2014-03-23 21:45 |只看该作者
本帖最后由 lylesong 于 2014-03-23 21:46 编辑

回复 4# OwnWaterloo


    恩,后面查资料看到了,http 1.1 里面对range, content-range的用法了,
但是别人都是从0开始,[中间划分几块] 最后到 length -1 为止。

axel 这个程序里面从1开始,也是到length -1为止,这里看了源码也没看明白,

你说的从1开始,1不要了,第0个字节抛弃了,文件还是完整的啊?

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
6 [报告]
发表于 2014-03-23 22:22 |只看该作者
回复 5# lylesong

刚才试了一下:

  1. $ curl -sI http://qianqian.baidu.com/download/BaiduMusic-12345630.exe | egrep -i '^(HTTP/|Content|Accept-Ranges)'
  2. HTTP/1.1 200 OK
  3. Content-Type: application/octet-stream
  4. Content-Length: 7421120
  5. Content-Type: application/octet-stream
  6. Content-Disposition: attachment; filename=BaiduMusic-12345630.exe
  7. Accept-Ranges: bytes
复制代码
支持Accept-Ranges,并且长度是7421120。

之后用

  1. $ axel http://qianqian.baidu.com/download/BaiduMusic-12345630.exe
复制代码
下载并且抓到下面一些请求:

GET /download/BaiduMusic-12345630.exe HTTP/1.0
Host: qianqian.baidu.com
Range: bytes=1-
User-Agent: Axel 2.4 (Linux)

HTTP/1.1 206 Partial Content
Server: nginx
Date: Sun, 23 Mar 2014 14:09:26 GMT
Content-Type: application/octet-stream
Content-Length: 7421119
Last-Modified: Wed, 04 Dec 2013 16:05:53 GMT
Connection: close
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=BaiduMusic-12345630.exe
Content-Range: bytes 1-7421119/7421120

GET /download/BaiduMusic-12345630.exe HTTP/1.0
Host: qianqian.baidu.com
Range: bytes=3710561-5565841
User-Agent: Axel 2.4 (Linux)

HTTP/1.1 206 Partial Content
Server: nginx
Date: Sun, 23 Mar 2014 14:09:26 GMT
Content-Type: application/octet-stream
Content-Length: 1855281
Last-Modified: Wed, 04 Dec 2013 16:05:53 GMT
Connection: close
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=BaiduMusic-12345630.exe
Content-Range: bytes 3710561-5565841/7421120

GET /download/BaiduMusic-12345630.exe HTTP/1.0
Host: qianqian.baidu.com
User-Agent: Axel 2.4 (Linux)

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 23 Mar 2014 14:09:26 GMT
Content-Type: application/octet-stream
Content-Length: 7421120
Last-Modified: Wed, 04 Dec 2013 16:05:53 GMT
Connection: close
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=BaiduMusic-12345630.exe
Accept-Ranges: bytes

GET /download/BaiduMusic-12345630.exe HTTP/1.0
Host: qianqian.baidu.com
Range: bytes=5565842-7421119
User-Agent: Axel 2.4 (Linux)

HTTP/1.1 206 Partial Content
Server: nginx
Date: Sun, 23 Mar 2014 14:09:26 GMT
Content-Type: application/octet-stream
Content-Length: 1855278
Last-Modified: Wed, 04 Dec 2013 16:05:53 GMT
Connection: close
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=BaiduMusic-12345630.exe
Content-Range: bytes 5565842-7421119/7421120

GET /download/BaiduMusic-12345630.exe HTTP/1.0
Host: qianqian.baidu.com
Range: bytes=1855280-3710560
User-Agent: Axel 2.4 (Linux)

HTTP/1.1 206 Partial Content
Server: nginx
Date: Sun, 23 Mar 2014 14:09:26 GMT
Content-Type: application/octet-stream
Content-Length: 1855281
Last-Modified: Wed, 04 Dec 2013 16:05:53 GMT
Connection: close
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=BaiduMusic-12345630.exe
Content-Range: bytes 1855280-3710560/7421120

确实第1个请求是Range: bytes=1-。 但后续也有一个没有带Range的请求。
不清楚为什么要这样处理。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP