diff options
author | coletdjnz <coletdjnz@protonmail.com> | 2023-07-15 15:55:23 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-07-15 16:18:35 +0530 |
commit | 227bf1a33be7b89cd7d44ad046844c4ccba104f4 (patch) | |
tree | 72ffa5e9135e7e4869c351bd9dec6c0944cfba17 /yt_dlp/downloader/http.py | |
parent | c365dba8430ee33abda85d31f95128605bf240eb (diff) | |
download | hypervideo-pre-227bf1a33be7b89cd7d44ad046844c4ccba104f4.tar.lz hypervideo-pre-227bf1a33be7b89cd7d44ad046844c4ccba104f4.tar.xz hypervideo-pre-227bf1a33be7b89cd7d44ad046844c4ccba104f4.zip |
[networking] Rewrite architecture (#2861)
New networking interface consists of a `RequestDirector` that directs
each `Request` to appropriate `RequestHandler` and returns the
`Response` or raises `RequestError`. The handlers define adapters to
transform its internal Request/Response/Errors to our interfaces.
User-facing changes:
- Fix issues with per request proxies on redirects for urllib
- Support for `ALL_PROXY` environment variable for proxy setting
- Support for `socks5h` proxy
- Closes https://github.com/yt-dlp/yt-dlp/issues/6325, https://github.com/ytdl-org/youtube-dl/issues/22618, https://github.com/ytdl-org/youtube-dl/pull/28093
- Raise error when using `https` proxy instead of silently converting it to `http`
Authored by: coletdjnz
Diffstat (limited to 'yt_dlp/downloader/http.py')
-rw-r--r-- | yt_dlp/downloader/http.py | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py index 7c5daea85..45d094721 100644 --- a/yt_dlp/downloader/http.py +++ b/yt_dlp/downloader/http.py @@ -1,12 +1,10 @@ -import http.client import os import random -import socket -import ssl import time import urllib.error from .common import FileDownloader +from ..networking.exceptions import CertificateVerifyError, TransportError from ..utils import ( ContentTooShortError, RetryManager, @@ -21,14 +19,6 @@ from ..utils import ( write_xattr, ) -RESPONSE_READ_EXCEPTIONS = ( - TimeoutError, - socket.timeout, # compat: py < 3.10 - ConnectionError, - ssl.SSLError, - http.client.HTTPException -) - class HttpFD(FileDownloader): def real_download(self, filename, info_dict): @@ -196,13 +186,9 @@ class HttpFD(FileDownloader): # Unexpected HTTP error raise raise RetryDownload(err) - except urllib.error.URLError as err: - if isinstance(err.reason, ssl.CertificateError): - raise - raise RetryDownload(err) - # In urllib.request.AbstractHTTPHandler, the response is partially read on request. - # Any errors that occur during this will not be wrapped by URLError - except RESPONSE_READ_EXCEPTIONS as err: + except CertificateVerifyError: + raise + except TransportError as err: raise RetryDownload(err) def close_stream(): @@ -258,7 +244,7 @@ class HttpFD(FileDownloader): try: # Download and write data_block = ctx.data.read(block_size if not is_test else min(block_size, data_len - byte_counter)) - except RESPONSE_READ_EXCEPTIONS as err: + except TransportError as err: retry(err) byte_counter += len(data_block) |