mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 14:58:38 +00:00
Absolute IPv6 addresses supported
This commit is contained in:
parent
18401dda8f
commit
11134b669e
@ -1,4 +1,5 @@
|
||||
import re
|
||||
from ipaddress import ip_address
|
||||
|
||||
# Allow underscore in host name
|
||||
_label_valid = re.compile(b"(?!-)[A-Z\d\-_]{1,63}(?<!-)$", re.IGNORECASE)
|
||||
@ -16,7 +17,13 @@ def is_valid_host(host: bytes) -> bool:
|
||||
return False
|
||||
if host and host[-1:] == b".":
|
||||
host = host[:-1]
|
||||
return all(_label_valid.match(x) for x in host.split(b"."))
|
||||
if all(_label_valid.match(x) for x in host.split(b".")):
|
||||
return True
|
||||
try:
|
||||
ip_address(host.decode('idna'))
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def is_valid_port(port):
|
||||
|
@ -11,3 +11,4 @@ def test_is_valid_host():
|
||||
assert check.is_valid_host(b"one.two.")
|
||||
# Allow underscore
|
||||
assert check.is_valid_host(b"one_two")
|
||||
assert check.is_valid_host(b"::1")
|
||||
|
Loading…
Reference in New Issue
Block a user