request.url now respects force_https_urls, closes #781

This commit is contained in:
Simon Willison 2020-05-28 10:09:32 -07:00
commit 7bb30c1f11
3 changed files with 14 additions and 0 deletions

View file

@ -786,6 +786,13 @@ class DatasetteRouter(AsgiRouter):
base_url = self.ds.config("base_url")
if base_url != "/" and path.startswith(base_url):
path = "/" + path[len(base_url) :]
# Apply force_https_urls, if set
if (
self.ds.config("force_https_urls")
and scope["type"] == "http"
and scope.get("scheme") != "https"
):
scope = dict(scope, scheme="https")
return await super().route_path(scope, receive, send, path)
async def handle_404(self, scope, receive, send, exception=None):