Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop HSTS Preloading #1110

Merged
merged 4 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ The HTTPX project relies on these excellent libraries:
* `h2` - HTTP/2 support.
* `certifi` - SSL certificates.
* `chardet` - Fallback auto-detection for response encoding.
* `hstspreload` - determines whether IDNA-encoded host should be only accessed via HTTPS.
* `idna` - Internationalized domain name support.
* `rfc3986` - URL parsing & normalization.
* `sniffio` - Async library autodetection.
Expand Down
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ The HTTPX project relies on these excellent libraries:
* `h2` - HTTP/2 support.
* `certifi` - SSL certificates.
* `chardet` - Fallback auto-detection for response encoding.
* `hstspreload` - determines whether IDNA-encoded host should be only accessed via HTTPS.
* `idna` - Internationalized domain name support.
* `rfc3986` - URL parsing & normalization.
* `sniffio` - Async library autodetection.
Expand Down
11 changes: 1 addition & 10 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import typing
from types import TracebackType

import hstspreload
import httpcore

from ._auth import Auth, BasicAuth, FunctionAuth
Expand Down Expand Up @@ -209,15 +208,7 @@ def _merge_url(self, url: URLTypes) -> URL:
Merge a URL argument together with any 'base_url' on the client,
to create the URL used for the outgoing request.
"""
url = self.base_url.join(relative_url=url)
if (
url.scheme == "http"
and hstspreload.in_hsts_preload(url.host)
and len(url.host.split(".")) > 1
):
port = None if url.port == 80 else url.port
url = url.copy_with(scheme="https", port=port)
return url
return self.base_url.join(relative_url=url)

def _merge_cookies(
self, cookies: CookieTypes = None
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ check_untyped_defs = True
profile = black
combine_as_imports = True
known_first_party = httpx,tests
known_third_party = brotli,certifi,chardet,cryptography,hstspreload,httpcore,pytest,rfc3986,setuptools,sniffio,trio,trustme,uvicorn
known_third_party = brotli,certifi,chardet,cryptography,httpcore,pytest,rfc3986,setuptools,sniffio,trio,trustme,uvicorn

[tool:pytest]
addopts = --cov=httpx --cov=tests -rxXs
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def get_packages(package):
zip_safe=False,
install_requires=[
"certifi",
"hstspreload",
"sniffio",
"chardet==3.*",
"idna==2.*",
Expand Down
23 changes: 4 additions & 19 deletions tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,10 @@ def test_base_url(server):


def test_merge_url():
client = httpx.Client(base_url="https://www.paypal.com/")
request = client.build_request("GET", "http://www.paypal.com")
assert request.url.scheme == "https"
assert request.url.is_ssl


@pytest.mark.parametrize(
"url,scheme,is_ssl",
[
("http://www.paypal.com", "https", True),
("http://app", "http", False),
("http://192.168.1.42", "http", False),
],
)
def test_merge_url_hsts(url: str, scheme: str, is_ssl: bool):
client = httpx.Client()
request = client.build_request("GET", url)
assert request.url.scheme == scheme
assert request.url.is_ssl == is_ssl
client = httpx.Client(base_url="https://www.example.com/")
request = client.build_request("GET", "http://www.example.com")
assert request.url.scheme == "http"
assert not request.url.is_ssl


def test_pool_limits_deprecated():
Expand Down