Uh oh!
There was an error while loading. Please reload this page.
Drop HSTS Preloading - #1110
Conversation
StephenBrown2
commented
Aug 3, 2020
Perhaps |
lovelydinosaur
commented
Aug 5, 2020
So, it's a wooly issue, but I think yes let's get this in and treat HSTS as appropriate as a browser feature, but not necessarily desirable in client library. |
StephenBrown2
commented
Aug 5, 2020
I would hate for the great work in the |
I'm trying to think of how people could enable this without us having to support it in core with a flag… I don't think a custom transport would be the way to go, since transports don't deal with client logic like "optionally modify the request URL". Probably more like a client subclass, then…? importhttpximporthstspreloadclassHSTSPreloadMixin:
defbuild_request(self, *args, **kwargs):
request=super().build_request(*args, **kwargs)
url=request.urlif (
url.scheme=="http"andhstspreload.in_hsts_preload(url.host)
andlen(url.host.split(".")) >1
):
port=Noneifurl.port==80elseurl.portrequest.url=url.copy_with(scheme="https", port=port)
returnrequestclassAsyncClient(HSTSPreloadMixin, httpx.AsyncClient):
passclassClient(HSTSPreloadMixin, httpx.Client):
passIncidentally I think this could also fit in a "middleware" kind of concept (#345, also mentioned in #984), but that's definitely not something we'll have 1.0. |
Possibly, but I was thinking of and even simpler approach/demonstration:
fromtypingimportUnionfromhttpximportURLfromhstspreloadimportin_hsts_preloaddefcheck_hsts(url: Union[str, URL]):
ifisinstance(url, str):
url=URL(url)
ifin_hsts_preload(url.host):
returnurl.copy_with(scheme="https")
returnurl... importhttpxfromutilimportcheck_hstshttpx.get(check_hsts(the_url))or with withhttpx.Client(base_url=check_hsts(the_url)) asclient:
client.get(path) |
Maybe? See the rationale in #1102
Fixes #1102, closes #896
Essentially:
I suppose if we want to move forward with this we'd want it in 0.14, rather than 1.0, since it might be a small breaking change?
Since this was an always-on feature not controlled by any options, I can't think of a smooth deprecation path, but any ideas welcome!