使用 wget 并手动传递 Range 标头

使用 wget 并手动传递 Range 标头

我想下载我明确定义的文件范围。据我所知:

wget --header="Range: bytes=1024-2048" http://www.example.com/file.tmp

应该可以正常运行。但是,当调试模式打开时,它却无法正常运行,并出现以下错误:

Registered socket 300 for persistent reuse.
Disabling further reuse of socket 300.
Closed fd 300

为什么它甚至会出现该错误并重试以及我该如何修复它?

以下是该过程的实际完整日志。

手动指定可续传下载

SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
Setting --server-response (serverresponse) to 1
Setting --page-requisites (pagerequisites) to 1
Setting --recursive (recursive) to 1
Setting --tries (tries) to 1
Setting --header (header) to Range: bytes=10024-
DEBUG output created by Wget 1.11.4 on Windows-MinGW.

Enqueuing http://www.example.com/file.tmp at depth 0
Queue count 1, maxcount 1.
Dequeuing http://www.example.com/file.tmp at depth 0
Queue count 0, maxcount 1.
--2012-01-11 07:02:46--  http:/www.example.com/file.tmp
www.example.com çözümleniyor... seconds 0,00, 127.0.0.1
Caching www.example.com => 127.0.0.1
www.example.com[127.0.0.1]:80 bağlanılıyor... seconds 0,00, bağlantı
kuruldu.
Created socket 300.
Releasing 0x0036a108 (new refcount 1).

---request begin---
GET /file.tmp HTTP/1.0
User-Agent: Wget/1.11.4
Accept: */*
Host: www.example.com
Connection: Keep-Alive
Range: bytes=10024-

---request end---
HTTP isteği gönderildi, yanıt bekleniyor...
---response begin---
HTTP/1.1 206 Partial Content
Server: nginx/0.7.65
Date: Wed, 11 Jan 2012 05:03:57 GMT
Content-Type: application/vnd.ms-powerpoint
Content-Length: 37651672
Last-Modified: Tue, 01 Nov 2011 21:18:50 GMT
Connection: keep-alive
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Content-Range: bytes 10024-37661695/37661696

---response end---

  HTTP/1.1 206 Partial Content
  Server: nginx/0.7.65
  Date: Wed, 11 Jan 2012 05:03:57 GMT
  Content-Type: application/vnd.ms-powerpoint
  Content-Length: 37651672
  Last-Modified: Tue, 01 Nov 2011 21:18:50 GMT
  Connection: keep-alive
  Expires: Thu, 31 Dec 2037 23:55:55 GMT
  Cache-Control: max-age=315360000
  Content-Range: bytes 10024-37661695/37661696
  Registered socket 300 for persistent reuse.
  Disabling further reuse of socket 300.
  Closed fd 300
  Vazgeçiliyor.

Wget支持断点续传下载(命令:-c)

SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
Setting --server-response (serverresponse) to 1
Setting --continue (continue) to 1
Setting --http-keep-alive (httpkeepalive) to 1
DEBUG output created by Wget 1.11.4 on Windows-MinGW.

--2012-01-11 07:12:51--  http://www.example.com/file.tmp
www.example.com çözümleniyor... seconds 0,00, 127.0.0.1
Caching www.example.com => 127.0.0.1
www.example.com[127.0.0.1]:80 bağlanılıyor... seconds 0,00, bağlantı
kuruldu.
Created socket 300.
Releasing 0x0003a0b0 (new refcount 1).

---request begin---
GET /file.tmp HTTP/1.0
Range: bytes=557172-
User-Agent: Wget/1.11.4
Accept: */*
Host: www.example.com
Connection: Keep-Alive

---request end---
HTTP isteği gönderildi, yanıt bekleniyor...
---response begin---
HTTP/1.1 206 Partial Content
Server: nginx/0.7.65
Date: Wed, 11 Jan 2012 05:14:01 GMT
Content-Type: application/vnd.ms-powerpoint
Content-Length: 37104524
Last-Modified: Tue, 01 Nov 2011 21:18:50 GMT
Connection: keep-alive
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Content-Range: bytes 557172-37661695/37661696

---response end---

  HTTP/1.1 206 Partial Content
  Server: nginx/0.7.65
  Date: Wed, 11 Jan 2012 05:14:01 GMT
  Content-Type: application/vnd.ms-powerpoint
  Content-Length: 37104524
  Last-Modified: Tue, 01 Nov 2011 21:18:50 GMT
  Connection: keep-alive
  Expires: Thu, 31 Dec 2037 23:55:55 GMT
  Cache-Control: max-age=315360000
  Content-Range: bytes 557172-37661695/37661696
Registered socket 300 for persistent reuse.
Uzunluk: 37661696 (36M), 37104524 (35M) kalan [application/vnd.ms-powerpoint]
Saving to: `file.tmp'

 1% [                                       ] 622.314      149K/s              ^

答案1

取决于你如何看待它,这要么是一个错误,要么是一个缺失的功能。

仅指定的标头--header由 Wget 发送,但不会被解释。

src/http.cWget 1.13.4 的 tarball 中,对部分内容进行了健全性检查:

  if ((contrange != 0 && contrange != hs->restval)
      || (H_PARTIAL (statcode) && !contrange))
    {
      /* The Range request was somehow misunderstood by the server.
         Bail out.  */
      xfree_null (type);
      CLOSE_INVALIDATE (sock);
      xfree (head);
      return RANGEERR;
    }

if条件包括两种情况:

  • 如果设置了内容范围,则它必须与正在下载的文件的缺失位数一致。

  • 如果发送部分内容,服务器必须指定内容范围。

第二种情况不会引起任何问题,因为 Wget 可以很好地解释服务器响应。但是第一种情况会引起问题,因为 Wget 不会解释客户端指定的范围。

为了解决这个问题,如果您愿意编译自己的 Wget 版本,您可以将上述源代码更改为以下内容:

  if (H_PARTIAL (statcode) && !contrange)
  {
      xfree_null (type);
      CLOSE_INVALIDATE (sock);
      xfree (head);
      return RANGEERR;
  }
  if (contrange != 0 && contrange != hs->restval)
    hs->restval = contrange;

现在,Wget 将从内容范围中扣除文件缺失的位数。

你也可以给卷曲试试看。它有一个内置--range开关。

相关内容