Skip to content

Commit

Permalink
default port for the socks5h scheme (#972)
Browse files Browse the repository at this point in the history
* default port for the socks5h scheme

* Update test_models.py

* Update test_models.py

* Update test_models.py
  • Loading branch information
mateuszlitwin authored Oct 28, 2024
1 parent 4e0a17c commit 0bfcee4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions httpcore/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 0bfcee4

Please sign in to comment.