from urllib.parse import parse_qsl, urlencode
import chardet
+import hstspreload
import rfc3986
from .config import USER_AGENT
if not self.host:
raise InvalidURL("No host included in URL.")
+ # If the URL is HTTP but the host is on the HSTS preload list switch to HTTPS.
+ if (
+ self.scheme == "http"
+ and self.host
+ and hstspreload.in_hsts_preload(self.host)
+ ):
+ self.components = self.components.copy_with(scheme="https")
+
@property
def scheme(self) -> str:
return self.components.scheme or ""
url_set = set(urls)
assert all(url in urls for url in url_set)
+
+
+def test_hsts_preload_converted_to_https():
+ url = URL("http://www.paypal.com")
+
+ assert url.is_ssl
+ assert url.scheme == "https"
+ assert url == "https://www.paypal.com"