Skip to content

Commit

Permalink
Internal scope correlation ID, refs #703
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 1, 2020
1 parent 61131f1 commit 6690d6b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import threading
import traceback
import urllib.parse
import uuid
from concurrent import futures
from pathlib import Path

Expand Down Expand Up @@ -856,13 +857,15 @@ 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) :]
# Add a correlation ID
scope_modifications = {"correlation_id": str(uuid.uuid4())}
# 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 @@ -874,7 +877,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

1 comment on commit 6690d6b

@simonw
Copy link
Owner Author

@simonw simonw commented on 6690d6b Jun 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also refs #790

Please sign in to comment.