Skip to content

Commit

Permalink
More efficient modifiation of scope
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 3, 2020
1 parent 3c5e4f2 commit 9690ce6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,13 +901,14 @@ async def route_path(self, scope, receive, send, path):
base_url = self.ds.config("base_url")
if base_url != "/" and path.startswith(base_url):
path = "/" + path[len(base_url) :]
scope_modifications = {}
# 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")
scope_modifications["scheme"] = "https"
# Handle authentication
actor = None
for actor in pm.hook.actor_from_request(
Expand All @@ -919,7 +920,10 @@ async def route_path(self, scope, receive, send, path):
actor = await actor
if actor:
break
return await super().route_path(dict(scope, actor=actor), receive, send, path)
scope_modifications["actor"] = actor
return await super().route_path(
dict(scope, **scope_modifications), receive, send, path
)

async def handle_404(self, scope, receive, send, exception=None):
# If URL has a trailing slash, redirect to URL without it
Expand Down

0 comments on commit 9690ce6

Please sign in to comment.