Skip to content
Myr

Skip HSTS preloading on single-label domains (#1074)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by François Voron · committed by GitHub · parent ad5e6eb · Browse files · 2 files+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

2 files+20 added−1 removed

  • tests:+15 added−0 removed
  • other:+5 added−1 removed

2 files+20 added−1 removed

modified:httpx/_client.py+5 added-1 removed
202 unmodified lines
203 Merge a URL argument together with any 'base_url' on the client,204 to create the URL used for the outgoing request.205 """206 url = self.base_url.join(relative_url=url)207 if url.scheme == "http" and hstspreload.in_hsts_preload(url.host):207 if (208 url.scheme == "http"209 and hstspreload.in_hsts_preload(url.host)210 and len(url.host.split(".")) > 1211 ):212 port = None if url.port == 80 else url.port213 url = url.copy_with(scheme="https", port=port)214 return url215
1304 unmodified lines
modified:tests/client/test_client.py+15 added
160 unmodified lines
161 client = httpx.Client(base_url="https://www.paypal.com/")162 request = client.build_request("GET", "http://www.paypal.com")163 assert request.url.scheme == "https"164 assert request.url.is_ssl165166167@pytest.mark.parametrize(168 "url,scheme,is_ssl",169 [170 ("http://www.paypal.com", "https", True),171 ("http://app", "http", False),172 ("http://192.168.1.42", "http", False),173 ],174)175def test_merge_url_hsts(url: str, scheme: str, is_ssl: bool):176 client = httpx.Client()177 request = client.build_request("GET", url)178 assert request.url.scheme == scheme179 assert request.url.is_ssl == is_ssl