From 0bfcee4cd266775c4d9ce2f89fc1b6afa8afc356 Mon Sep 17 00:00:00 2001 From: Mateusz Litwin Date: Mon, 28 Oct 2024 10:40:48 -0700 Subject: [PATCH] default port for the socks5h scheme (#972) * default port for the socks5h scheme * Update test_models.py * Update test_models.py * Update test_models.py --- httpcore/_models.py | 1 + tests/test_models.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/httpcore/_models.py b/httpcore/_models.py index 48e10317..c739a7fa 100644 --- a/httpcore/_models.py +++ b/httpcore/_models.py @@ -284,6 +284,7 @@ def origin(self) -> Origin: b"ws": 80, b"wss": 443, b"socks5": 1080, + b"socks5h": 1080, }[self.scheme] return Origin( scheme=self.scheme, host=self.host, port=self.port or default_port diff --git a/tests/test_models.py b/tests/test_models.py index 35b6e947..7dd6e419 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -41,6 +41,18 @@ def test_url_cannot_include_unicode_strings(): httpcore.URL(scheme=b"https", host=b"www.example.com", target="/☺".encode("utf-8")) +def test_url_origin_socks5(): + url = httpcore.URL("socks5://127.0.0.1") + origin = url.origin + assert origin == httpcore.Origin(scheme=b"socks5", host=b"127.0.0.1", port=1080) + assert str(origin) == "socks5://127.0.0.1:1080" + + url = httpcore.URL("socks5h://127.0.0.1") + origin = url.origin + assert origin == httpcore.Origin(scheme=b"socks5h", host=b"127.0.0.1", port=1080) + assert str(origin) == "socks5h://127.0.0.1:1080" + + # Request