有個同事說,發現現在對外下載安裝包的服務器不支持斷點續傳,我聽了一陣納悶,lighttpd server對於靜態文件應該默認支持斷點續傳的,登機器查看lighttpd配置文件發現
對斷點續傳的支持被禁用了,lighttpd的說明里對該配置是這樣表述的:
server.range-requests
Allowed values: enable , disable
Default: enable
This option defines whether range requests are allowed or not.
Range request are requests of one or more sub-ranges of a file. Range requests are very helpful for resuming interrupted downloads and fetching small portions of huge files.
對於PDF還有特殊的說明,斷點續傳pdf的時候會crash
Note: Adobe Acrobat Reader can crash when it tries to open a PDF file if range requests are enabled.
用以下匹配規則設置對pdf文件斷點續傳的禁用
$HTTP["url"] =~ "\.pdf$" { server.range-requests = "disable" }
然后,想怎么能馬上檢查一個服務器是否支持斷點續傳,用curl實現
$ curl -r 0-1 -o range_test.part1 'url'
其中url為文件的下載地址
如果在目錄下生成了一個2字節大小的 range_test.part1 文件,那么說明服務器支持斷點續傳,如果把整個文件拉下來了,說明不支持
剛寫完就被同事說直接curl -I 就能馬上看出來服務器是否支持斷點續傳,執行
$ curl -I 'url'
看返回的http頭信息,如果有 Accept-Ranges: bytes 表示服務器支持Range請求,以及服務器所支持的單位是字節(這也是唯一可用的單位)。並且,服務器支持斷點續傳,以及支持同時下載文件的多個部分,也就是說下載工具可以利用范圍請求加速下載該文件。如果有 Accept-Ranges: none 響應頭表示服務器不支持范圍請求。
例如:
$ curl -I http://zhangmenshiting.baidu.com/data2/music/118358164/14385500158400128.mp3
返回
HTTP/1.1 200 OK Accept-Ranges: bytes Last-Modified: Tue, 22 Apr 2014 12:42:15 GMT Expires: Sun, 25 May 2014 11:22:57 GMT x-bs-version: D18E23AE8230A245A8EB6B77EFA5B92D ETag: d5bd29010e1bf1c861d4b34f0f74a968 Content-Type: audio/mpeg x-bs-request-id: MTAuNDYuMTU4LjIxOjgwODA6MTQ1MzE2ODg3ODoyNS9BcHIvMjAxNCAxOToyMjo1NyA= Content-Disposition: attachment; filename="ʱ¼䶼ȥń¶魭p3" x-bs-meta-crc32: 3366589278 Content-MD5: d5bd29010e1bf1c861d4b34f0f74a968 x-bs-client-ip: MTE1LjIzOS4yMTIuMTMz x-bs-uncopyable: enable Cache-Control: max-age=2592000 Content-Length: 3537110 Connection: close Date: Fri, 25 Apr 2014 11:22:57 GMT Server: BaiduBS
說明服務器支持范圍請求和斷點續傳,換一個
$ curl -I http://www.taobao.com
返回
HTTP/1.1 200 OK Server: Tengine Date: Fri, 25 Apr 2014 11:26:06 GMT Content-Type: text/html; charset=gbk Connection: keep-alive Vary: Accept-Encoding Expires: Fri, 25 Apr 2014 12:26:06 GMT Cache-Control: max-age=3600
就不支持