Skip to content

Commit

Permalink
http3_client.py: fixup 2nd and later urls
Browse files Browse the repository at this point in the history
- Check if all urls are in the same host and scheme.
- If url argument is partial (e.g. without https://),
  fill in fields from 1st url.
  • Loading branch information
junhochoi authored and jlaine committed May 9, 2022
1 parent 7c411b6 commit d272be1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/http3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,25 @@ async def run(
else:
port = 443

# check validity of 2nd urls and later.
for i in range(1, len(urls)):
_p = urlparse(urls[i])

# fill in if empty
_scheme = _p.scheme or parsed.scheme
_host = _p.hostname or host
_port = _p.port or port

assert _scheme == parsed.scheme, "URL scheme doesn't match"
assert _host == host, "URL hostname doesn't match"
assert _port == port, "URL port doesn't match"

# reconstruct url with new hostname and port
_p = _p._replace(scheme=_scheme)
_p = _p._replace(netloc="{}:{}".format(_host, _port))
_p = urlparse(_p.geturl())
urls[i] = _p.geturl()

async with connect(
host,
port,
Expand Down

0 comments on commit d272be1

Please sign in to comment.