如何从url获取文件的缺少内容长度?

时间:2020-08-08 12:12:52

标签: python python-requests http-headers download-manager http-content-length

我正在尝试并发编写simple download manager using python。目的是使用文件URL响应中的Content-Length头,并将文件拆分为多个块,然后同时下载这些块。这个想法适用于所有带有Content-Length标头的网址,但最近我遇到了一些不提供Content-Length标头的网址。

https://filesamples.com/samples/audio/mp3/sample3.mp3

HTTP/1.1 200 OK
Date:   Sat, 08 Aug 2020 11:53:15 GMT
Content-Type:   audio/mpeg
Transfer-Encoding:  chunked
Connection: close
Set-Cookie: __cfduid=d2a4be3535695af67cb7a7efe5add19bf1596887595; expires=Mon, 07-Sep-20 11:53:15 GMT; path=/; domain=.filesamples.com; HttpOnly; SameSite=Lax
Cache-Control:  public, max-age=86400
Display:    staticcontent_sol, staticcontent_sol
Etag:   W/"5def04f1-19d6dd-gzip"
Last-Modified:  Fri, 31 Jul 2020 21:52:34 GMT
Response:   200
Vary:   Accept-Encoding
Vary:   User-Agent,Origin,Accept-Encoding
X-Ezoic-Cdn:    Miss
X-Middleton-Display:    staticcontent_sol, staticcontent_sol
X-Middleton-Response:   200
CF-Cache-Status:    HIT
Age:    24
cf-request-id:  046f8413ab0000e047449da200000001
Expect-CT:  max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5bf90932ae53e047-SEA

如何在不下载整个文件的情况下获得文件的内容长度?

0 个答案:

没有答案