Skip to content
Myr

Switch hosts on HSTS preload to HTTPS (#151)

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

authored by Seth Michael Larson · committed by GitHub · parent 7e9110b · Browse files · 4 files+19 added−0 removed
This commit

State

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

Diff stats

4 files+19 added−0 removed

  • tests:+8 added−0 removed
  • other:+11 added−0 removed

4 files+19 added−0 removed

modified:httpx/models.py+9 added
6 unmodified lines
7from http.cookiejar import Cookie, CookieJar8from urllib.parse import parse_qsl, urlencode910import chardet11import hstspreload12import rfc39861314from .config import USER_AGENT15from .decoders import (
97 unmodified lines
113 raise InvalidURL("No scheme included in URL.")114 if not self.host:115 raise InvalidURL("No host included in URL.")116117 # If the URL is HTTP but the host is on the HSTS preload list switch to HTTPS.118 if (119 self.scheme == "http"120 and self.host121 and hstspreload.in_hsts_preload(self.host)122 ):123 self.components = self.components.copy_with(scheme="https")124125 @property126 def scheme(self) -> str:127 return self.components.scheme or ""128
1050 unmodified lines
modified:tests/models/test_url.py+8 added
122 unmodified lines
123124 url_set = set(urls)125126 assert all(url in urls for url in url_set)127128129def test_hsts_preload_converted_to_https():130 url = URL("http://www.paypal.com")131132 assert url.is_ssl133 assert url.scheme == "https"134 assert url == "https://www.paypal.com"
modified:requirements.txt+1 added
1certifi2chardet==3.*3h11==0.8.*4h2==3.*5hstspreload6idna==2.*7rfc3986==1.*89# Optional
20 unmodified lines
modified:setup.py+1 added
49 unmodified lines
50 "certifi",51 "chardet==3.*",52 "h11==0.8.*",53 "h2==3.*",54 "hstspreload",55 "idna==2.*",56 "rfc3986==1.*",57 ],58 classifiers=[
12 unmodified lines