mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Use single Request created in DatasetteRouter, refs #870
This commit is contained in:
parent
4dad028432
commit
af350ba457
1 changed files with 12 additions and 12 deletions
|
|
@ -925,6 +925,7 @@ class DatasetteRouter:
|
||||||
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) :]
|
||||||
|
request = Request(scope, receive)
|
||||||
scope_modifications = {}
|
scope_modifications = {}
|
||||||
# Apply force_https_urls, if set
|
# Apply force_https_urls, if set
|
||||||
if (
|
if (
|
||||||
|
|
@ -936,9 +937,7 @@ class DatasetteRouter:
|
||||||
# Handle authentication
|
# Handle authentication
|
||||||
default_actor = scope.get("actor") or None
|
default_actor = scope.get("actor") or None
|
||||||
actor = None
|
actor = None
|
||||||
for actor in pm.hook.actor_from_request(
|
for actor in pm.hook.actor_from_request(datasette=self.ds, request=request):
|
||||||
datasette=self.ds, request=Request(scope, receive)
|
|
||||||
):
|
|
||||||
if callable(actor):
|
if callable(actor):
|
||||||
actor = actor()
|
actor = actor()
|
||||||
if asyncio.iscoroutine(actor):
|
if asyncio.iscoroutine(actor):
|
||||||
|
|
@ -951,8 +950,9 @@ class DatasetteRouter:
|
||||||
match = regex.match(path)
|
match = regex.match(path)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
new_scope = dict(scope, url_route={"kwargs": match.groupdict()})
|
new_scope = dict(scope, url_route={"kwargs": match.groupdict()})
|
||||||
|
request.scope = new_scope
|
||||||
try:
|
try:
|
||||||
return await view(Request(new_scope, receive), send)
|
return await view(request, send)
|
||||||
except NotFound as exception:
|
except NotFound as exception:
|
||||||
return await self.handle_404(scope, receive, send, exception)
|
return await self.handle_404(scope, receive, send, exception)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
|
|
@ -1079,26 +1079,26 @@ def _cleaner_task_str(task):
|
||||||
|
|
||||||
|
|
||||||
def wrap_view(view_fn, datasette):
|
def wrap_view(view_fn, datasette):
|
||||||
async def asgi_view_fn(scope, receive, send):
|
async def async_view_fn(request, send):
|
||||||
if inspect.iscoroutinefunction(view_fn):
|
if inspect.iscoroutinefunction(view_fn):
|
||||||
response = await async_call_with_supported_arguments(
|
response = await async_call_with_supported_arguments(
|
||||||
view_fn,
|
view_fn,
|
||||||
scope=scope,
|
scope=request.scope,
|
||||||
receive=receive,
|
receive=request.receive,
|
||||||
send=send,
|
send=send,
|
||||||
request=Request(scope, receive),
|
request=request,
|
||||||
datasette=datasette,
|
datasette=datasette,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
response = call_with_supported_arguments(
|
response = call_with_supported_arguments(
|
||||||
view_fn,
|
view_fn,
|
||||||
scope=scope,
|
scope=request.scope,
|
||||||
receive=receive,
|
receive=request.receive,
|
||||||
send=send,
|
send=send,
|
||||||
request=Request(scope, receive),
|
request=request,
|
||||||
datasette=datasette,
|
datasette=datasette,
|
||||||
)
|
)
|
||||||
if response is not None:
|
if response is not None:
|
||||||
await response.asgi_send(send)
|
await response.asgi_send(send)
|
||||||
|
|
||||||
return asgi_view_fn
|
return async_view_fn
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue