misc cleanup

This commit is contained in:
coletdjnz 2024-04-06 15:50:48 +13:00
parent eecdc5870c
commit 833862cfbc
No known key found for this signature in database
GPG Key ID: 91984263BB39894A
2 changed files with 8 additions and 18 deletions

View File

@ -8,7 +8,7 @@ import random
import ssl
import threading
from http.server import BaseHTTPRequestHandler
from socketserver import ThreadingTCPServer
from socketserver import BaseRequestHandler, ThreadingTCPServer
import pytest
@ -224,7 +224,7 @@ def proxy_server(proxy_server_class, request_handler, bind_ip=None, **proxy_serv
finally:
server.shutdown()
server.server_close()
server_thread.join()
server_thread.join(2.0)
class HTTPProxyTestContext(abc.ABC):
@ -304,7 +304,6 @@ class TestHTTPProxy:
assert proxy_info['proxy'] == server_address
assert proxy_info['connect'] is False
assert 'Proxy-Authorization' not in proxy_info['headers']
assert proxy_info['proxy'] == server_address
def test_http_auth(self, handler, ctx):
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['connect'] is False
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')
def test_https_verify_failed(self, handler, ctx):
@ -358,7 +356,6 @@ class TestHTTPProxy:
assert proxy_info['proxy'] == server_address
assert proxy_info['path'].startswith('http://xn--fiq228c.tw')
assert proxy_info['headers']['Host'].split(':', 1)[0] == 'xn--fiq228c.tw'
assert proxy_info['proxy'] == server_address
@pytest.mark.parametrize(
@ -376,7 +373,6 @@ class TestHTTPConnectProxy:
assert proxy_info['proxy'] == server_address
assert proxy_info['connect'] is True
assert 'Proxy-Authorization' not in proxy_info['headers']
assert proxy_info['proxy'] == server_address
def test_http_connect_auth(self, handler, ctx):
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)
assert proxy_info['proxy'] == server_address
assert 'Proxy-Authorization' in proxy_info['headers']
assert proxy_info['proxy'] == server_address
@pytest.mark.skip_handler(
'Requests',
@ -415,7 +410,6 @@ class TestHTTPConnectProxy:
assert proxy_info['proxy'] == server_address
assert proxy_info['connect'] is True
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')
def test_https_connect_verify_failed(self, handler, ctx):
@ -434,4 +428,3 @@ class TestHTTPConnectProxy:
proxy_info = ctx.proxy_info_request(rh)
assert proxy_info['proxy'] == server_address
assert 'Proxy-Authorization' in proxy_info['headers']
assert proxy_info['proxy'] == server_address

View File

@ -1,10 +1,13 @@
from __future__ import annotations
import base64
import contextlib
import io
import logging
import ssl
import sys
import urllib.parse
from http.client import HTTPConnection, HTTPResponse
from ._helper import (
create_connection,
@ -19,19 +22,14 @@ from .exceptions import (
ProxyError,
RequestError,
SSLError,
TransportError, UnsupportedRequest,
TransportError,
UnsupportedRequest,
)
from .websocket import WebSocketRequestHandler, WebSocketResponse
from ..compat import functools
from ..dependencies import websockets, urllib3
from ..dependencies import urllib3, websockets
from ..socks import ProxyError as SocksProxyError
from ..utils import int_or_none
import io
import urllib.parse
import base64
from http.client import HTTPResponse, HTTPConnection
from ..utils.networking import HTTPHeaderDict
if not websockets:
@ -282,7 +280,6 @@ def create_http_connect_conn(
password=None,
):
# todo: handle ipv6 host
proxy_headers = HTTPHeaderDict({
**(headers or {}),
})