mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Internal scope correlation ID, refs #703
This commit is contained in:
parent
61131f1fd7
commit
6690d6bf7f
1 changed files with 8 additions and 2 deletions
|
|
@ -10,6 +10,7 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import uuid
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
@ -856,13 +857,15 @@ class DatasetteRouter(AsgiRouter):
|
||||||
base_url = self.ds.config("base_url")
|
base_url = self.ds.config("base_url")
|
||||||
if base_url != "/" and path.startswith(base_url):
|
if base_url != "/" and path.startswith(base_url):
|
||||||
path = "/" + path[len(base_url) :]
|
path = "/" + path[len(base_url) :]
|
||||||
|
# Add a correlation ID
|
||||||
|
scope_modifications = {"correlation_id": str(uuid.uuid4())}
|
||||||
# Apply force_https_urls, if set
|
# Apply force_https_urls, if set
|
||||||
if (
|
if (
|
||||||
self.ds.config("force_https_urls")
|
self.ds.config("force_https_urls")
|
||||||
and scope["type"] == "http"
|
and scope["type"] == "http"
|
||||||
and scope.get("scheme") != "https"
|
and scope.get("scheme") != "https"
|
||||||
):
|
):
|
||||||
scope = dict(scope, scheme="https")
|
scope_modifications["scheme"] = "https"
|
||||||
# Handle authentication
|
# Handle authentication
|
||||||
actor = None
|
actor = None
|
||||||
for actor in pm.hook.actor_from_request(
|
for actor in pm.hook.actor_from_request(
|
||||||
|
|
@ -874,7 +877,10 @@ class DatasetteRouter(AsgiRouter):
|
||||||
actor = await actor
|
actor = await actor
|
||||||
if actor:
|
if actor:
|
||||||
break
|
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):
|
async def handle_404(self, scope, receive, send, exception=None):
|
||||||
# If URL has a trailing slash, redirect to URL without it
|
# If URL has a trailing slash, redirect to URL without it
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue