mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-02-11 20:47:55 +01:00
misc cleanup
This commit is contained in:
parent
eecdc5870c
commit
833862cfbc
2 changed files with 8 additions and 18 deletions
|
@ -8,7 +8,7 @@ import random
|
||||||
import ssl
|
import ssl
|
||||||
import threading
|
import threading
|
||||||
from http.server import BaseHTTPRequestHandler
|
from http.server import BaseHTTPRequestHandler
|
||||||
from socketserver import ThreadingTCPServer
|
from socketserver import BaseRequestHandler, ThreadingTCPServer
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ def proxy_server(proxy_server_class, request_handler, bind_ip=None, **proxy_serv
|
||||||
finally:
|
finally:
|
||||||
server.shutdown()
|
server.shutdown()
|
||||||
server.server_close()
|
server.server_close()
|
||||||
server_thread.join()
|
server_thread.join(2.0)
|
||||||
|
|
||||||
|
|
||||||
class HTTPProxyTestContext(abc.ABC):
|
class HTTPProxyTestContext(abc.ABC):
|
||||||
|
@ -304,7 +304,6 @@ class TestHTTPProxy:
|
||||||
assert proxy_info['proxy'] == server_address
|
assert proxy_info['proxy'] == server_address
|
||||||
assert proxy_info['connect'] is False
|
assert proxy_info['connect'] is False
|
||||||
assert 'Proxy-Authorization' not in proxy_info['headers']
|
assert 'Proxy-Authorization' not in proxy_info['headers']
|
||||||
assert proxy_info['proxy'] == server_address
|
|
||||||
|
|
||||||
def test_http_auth(self, handler, ctx):
|
def test_http_auth(self, handler, ctx):
|
||||||
with ctx.http_server(HTTPProxyHandler, username='test', password='test') as server_address:
|
with ctx.http_server(HTTPProxyHandler, username='test', password='test') as server_address:
|
||||||
|
@ -339,7 +338,6 @@ class TestHTTPProxy:
|
||||||
assert proxy_info['proxy'] == server_address
|
assert proxy_info['proxy'] == server_address
|
||||||
assert proxy_info['connect'] is False
|
assert proxy_info['connect'] is False
|
||||||
assert 'Proxy-Authorization' not in proxy_info['headers']
|
assert 'Proxy-Authorization' not in proxy_info['headers']
|
||||||
assert proxy_info['proxy'] == server_address
|
|
||||||
|
|
||||||
@pytest.mark.skip_handler('Urllib', 'urllib does not support https proxies')
|
@pytest.mark.skip_handler('Urllib', 'urllib does not support https proxies')
|
||||||
def test_https_verify_failed(self, handler, ctx):
|
def test_https_verify_failed(self, handler, ctx):
|
||||||
|
@ -358,7 +356,6 @@ class TestHTTPProxy:
|
||||||
assert proxy_info['proxy'] == server_address
|
assert proxy_info['proxy'] == server_address
|
||||||
assert proxy_info['path'].startswith('http://xn--fiq228c.tw')
|
assert proxy_info['path'].startswith('http://xn--fiq228c.tw')
|
||||||
assert proxy_info['headers']['Host'].split(':', 1)[0] == 'xn--fiq228c.tw'
|
assert proxy_info['headers']['Host'].split(':', 1)[0] == 'xn--fiq228c.tw'
|
||||||
assert proxy_info['proxy'] == server_address
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -376,7 +373,6 @@ class TestHTTPConnectProxy:
|
||||||
assert proxy_info['proxy'] == server_address
|
assert proxy_info['proxy'] == server_address
|
||||||
assert proxy_info['connect'] is True
|
assert proxy_info['connect'] is True
|
||||||
assert 'Proxy-Authorization' not in proxy_info['headers']
|
assert 'Proxy-Authorization' not in proxy_info['headers']
|
||||||
assert proxy_info['proxy'] == server_address
|
|
||||||
|
|
||||||
def test_http_connect_auth(self, handler, ctx):
|
def test_http_connect_auth(self, handler, ctx):
|
||||||
with ctx.http_server(HTTPConnectProxyHandler, username='test', password='test') as server_address:
|
with ctx.http_server(HTTPConnectProxyHandler, username='test', password='test') as server_address:
|
||||||
|
@ -384,7 +380,6 @@ class TestHTTPConnectProxy:
|
||||||
proxy_info = ctx.proxy_info_request(rh)
|
proxy_info = ctx.proxy_info_request(rh)
|
||||||
assert proxy_info['proxy'] == server_address
|
assert proxy_info['proxy'] == server_address
|
||||||
assert 'Proxy-Authorization' in proxy_info['headers']
|
assert 'Proxy-Authorization' in proxy_info['headers']
|
||||||
assert proxy_info['proxy'] == server_address
|
|
||||||
|
|
||||||
@pytest.mark.skip_handler(
|
@pytest.mark.skip_handler(
|
||||||
'Requests',
|
'Requests',
|
||||||
|
@ -415,7 +410,6 @@ class TestHTTPConnectProxy:
|
||||||
assert proxy_info['proxy'] == server_address
|
assert proxy_info['proxy'] == server_address
|
||||||
assert proxy_info['connect'] is True
|
assert proxy_info['connect'] is True
|
||||||
assert 'Proxy-Authorization' not in proxy_info['headers']
|
assert 'Proxy-Authorization' not in proxy_info['headers']
|
||||||
assert proxy_info['proxy'] == server_address
|
|
||||||
|
|
||||||
@pytest.mark.skipif(urllib3 is None, reason='requires urllib3 to test')
|
@pytest.mark.skipif(urllib3 is None, reason='requires urllib3 to test')
|
||||||
def test_https_connect_verify_failed(self, handler, ctx):
|
def test_https_connect_verify_failed(self, handler, ctx):
|
||||||
|
@ -434,4 +428,3 @@ class TestHTTPConnectProxy:
|
||||||
proxy_info = ctx.proxy_info_request(rh)
|
proxy_info = ctx.proxy_info_request(rh)
|
||||||
assert proxy_info['proxy'] == server_address
|
assert proxy_info['proxy'] == server_address
|
||||||
assert 'Proxy-Authorization' in proxy_info['headers']
|
assert 'Proxy-Authorization' in proxy_info['headers']
|
||||||
assert proxy_info['proxy'] == server_address
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import base64
|
||||||
import contextlib
|
import contextlib
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import ssl
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
|
import urllib.parse
|
||||||
|
from http.client import HTTPConnection, HTTPResponse
|
||||||
|
|
||||||
from ._helper import (
|
from ._helper import (
|
||||||
create_connection,
|
create_connection,
|
||||||
|
@ -19,19 +22,14 @@ from .exceptions import (
|
||||||
ProxyError,
|
ProxyError,
|
||||||
RequestError,
|
RequestError,
|
||||||
SSLError,
|
SSLError,
|
||||||
TransportError, UnsupportedRequest,
|
TransportError,
|
||||||
|
UnsupportedRequest,
|
||||||
)
|
)
|
||||||
from .websocket import WebSocketRequestHandler, WebSocketResponse
|
from .websocket import WebSocketRequestHandler, WebSocketResponse
|
||||||
from ..compat import functools
|
from ..compat import functools
|
||||||
from ..dependencies import websockets, urllib3
|
from ..dependencies import urllib3, websockets
|
||||||
from ..socks import ProxyError as SocksProxyError
|
from ..socks import ProxyError as SocksProxyError
|
||||||
from ..utils import int_or_none
|
from ..utils import int_or_none
|
||||||
import io
|
|
||||||
import urllib.parse
|
|
||||||
import base64
|
|
||||||
|
|
||||||
from http.client import HTTPResponse, HTTPConnection
|
|
||||||
|
|
||||||
from ..utils.networking import HTTPHeaderDict
|
from ..utils.networking import HTTPHeaderDict
|
||||||
|
|
||||||
if not websockets:
|
if not websockets:
|
||||||
|
@ -282,7 +280,6 @@ def create_http_connect_conn(
|
||||||
password=None,
|
password=None,
|
||||||
):
|
):
|
||||||
|
|
||||||
# todo: handle ipv6 host
|
|
||||||
proxy_headers = HTTPHeaderDict({
|
proxy_headers = HTTPHeaderDict({
|
||||||
**(headers or {}),
|
**(headers or {}),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue