xtr-http-kernel 6.6.0__tar.gz → 6.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/PKG-INFO +14 -4
  2. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/README.md +11 -1
  3. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/pyproject.toml +3 -3
  4. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/pyproject.toml.orig +11 -4
  5. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/SKILL.md +10 -4
  6. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/_kernel_middleware.py +10 -3
  7. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/_route_contexts.py +11 -41
  8. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/served_connection.py +12 -10
  9. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/LICENSE +0 -0
  10. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/configure.md +0 -0
  11. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/listeners.md +0 -0
  12. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/rate-limits.md +0 -0
  13. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/routing.md +0 -0
  14. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/__init__.py +0 -0
  15. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/_staging.py +0 -0
  16. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/_state.py +0 -0
  17. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/__init__.py +0 -0
  18. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/_headers.py +0 -0
  19. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/_media_types.py +0 -0
  20. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/_scope_uri.py +0 -0
  21. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/_server_params.py +0 -0
  22. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/http_message_factory.py +0 -0
  23. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/http_message_factory_interface.py +0 -0
  24. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/response.py +0 -0
  25. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/response_factory.py +0 -0
  26. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/starlette_http_factory.py +0 -0
  27. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bridge/starlette_http_factory_interface.py +0 -0
  28. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bundle/__init__.py +0 -0
  29. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bundle/_messages.py +0 -0
  30. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bundle/http_kernel_bundle.py +0 -0
  31. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bundle/http_kernel_config.py +0 -0
  32. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bundle/request_lifecycle_middleware_factory.py +0 -0
  33. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/bundle/route_registry_pass.py +0 -0
  34. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/command/__init__.py +0 -0
  35. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/command/debug_router_command.py +0 -0
  36. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/command/route_description.py +0 -0
  37. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/command/router_command.py +0 -0
  38. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/command/router_match_command.py +0 -0
  39. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event/__init__.py +0 -0
  40. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event/exception_event.py +0 -0
  41. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event/finish_request_event.py +0 -0
  42. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event/request_event.py +0 -0
  43. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event/response_event.py +0 -0
  44. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event/terminate_event.py +0 -0
  45. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event_listener/__init__.py +0 -0
  46. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event_listener/disallow_robots_indexing_listener.py +0 -0
  47. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event_listener/error_logging_listener.py +0 -0
  48. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event_listener/log_unit_listener.py +0 -0
  49. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event_listener/rate_limit_headers_listener.py +0 -0
  50. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/event_listener/request_id_listener.py +0 -0
  51. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/__init__.py +0 -0
  52. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/http_kernel_error.py +0 -0
  53. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/invalid_argument_error.py +0 -0
  54. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/invalid_cookie_error.py +0 -0
  55. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/invalid_middleware_priority_error.py +0 -0
  56. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/invalid_rate_limit_error.py +0 -0
  57. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/ranged_response_body_error.py +0 -0
  58. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/response_already_a_message_error.py +0 -0
  59. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/streamed_response_body_error.py +0 -0
  60. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/too_many_requests_error.py +0 -0
  61. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/unknown_rate_limiter_error.py +0 -0
  62. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/exception/unsupported_connection_error.py +0 -0
  63. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/kernel_events.py +0 -0
  64. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/middleware_stack.py +0 -0
  65. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/middleware_tag.py +0 -0
  66. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/py.typed +0 -0
  67. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/rate_limiter/__init__.py +0 -0
  68. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/rate_limiter/_applied_rate_limit.py +0 -0
  69. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/rate_limiter/rate_limited.py +0 -0
  70. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/recipe/__init__.py +0 -0
  71. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/recipe/files/config/http_kernel.py.tmpl +0 -0
  72. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/recipe/manifest.toml +0 -0
  73. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/request_lifecycle_middleware.py +0 -0
  74. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/__init__.py +0 -0
  75. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/decorator/__init__.py +0 -0
  76. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/decorator/as_route_resource.py +0 -0
  77. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/decorator/as_routes.py +0 -0
  78. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/exception/__init__.py +0 -0
  79. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/exception/invalid_argument_error.py +0 -0
  80. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/exception/route_conflict_error.py +0 -0
  81. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/exception/routing_error.py +0 -0
  82. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/routing/route_registry.py +0 -0
  83. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/setup.py +0 -0
  84. {xtr_http_kernel-6.6.0 → xtr_http_kernel-6.8.0}/src/xtr_http_kernel/testing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xtr-http-kernel
3
- Version: 6.6.0
3
+ Version: 6.8.0
4
4
  Summary: Requests turned into responses through events: a request lifecycle for FastAPI applications on the xtr kernel.
5
5
  Keywords: http,kernel,request,lifecycle,events,middleware,fastapi
6
6
  Author: Xterr
@@ -14,8 +14,8 @@ Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
16
  Classifier: Typing :: Typed
17
- Requires-Dist: fastapi>=0.121.3
18
- Requires-Dist: starlette>=0.40
17
+ Requires-Dist: fastapi>=0.143.1
18
+ Requires-Dist: starlette>=1.3.1
19
19
  Requires-Dist: xtr-dependency-injection>=6.0,<7
20
20
  Requires-Dist: xtr-event-dispatcher>=6.0,<7
21
21
  Requires-Dist: xtr-event-dispatcher-contracts>=6.0,<7
@@ -118,9 +118,19 @@ setup(app, kernel)
118
118
  Serve it with any ASGI server:
119
119
 
120
120
  ```sh
121
- uv run --with uvicorn uvicorn --app-dir . app:app
121
+ uv run --with 'uvicorn>=0.45' uvicorn --reset-contextvars --app-dir . app:app
122
122
  ```
123
123
 
124
+ `--reset-contextvars` starts each request in a context of its own. A server gives no promise
125
+ about the context a request's task starts with: on a kept-alive connection it can be a copy of
126
+ an earlier request's, taken while that request was being served. What this package keeps per
127
+ request — the scope its services live in, the request a service is handed — is found on the
128
+ request's own connection and is its own either way. A context variable the application sets,
129
+ or one a library it uses sets, has no such anchor: only the server can keep it from reaching
130
+ the next request, and the flag is how it is asked to. With it on, a context variable set
131
+ before the server started is not seen by a request; pass such a value through the
132
+ application's state.
133
+
124
134
  ```console
125
135
  $ curl -i localhost:8000/books/0262510871
126
136
  HTTP/1.1 200 OK
@@ -88,9 +88,19 @@ setup(app, kernel)
88
88
  Serve it with any ASGI server:
89
89
 
90
90
  ```sh
91
- uv run --with uvicorn uvicorn --app-dir . app:app
91
+ uv run --with 'uvicorn>=0.45' uvicorn --reset-contextvars --app-dir . app:app
92
92
  ```
93
93
 
94
+ `--reset-contextvars` starts each request in a context of its own. A server gives no promise
95
+ about the context a request's task starts with: on a kept-alive connection it can be a copy of
96
+ an earlier request's, taken while that request was being served. What this package keeps per
97
+ request — the scope its services live in, the request a service is handed — is found on the
98
+ request's own connection and is its own either way. A context variable the application sets,
99
+ or one a library it uses sets, has no such anchor: only the server can keep it from reaching
100
+ the next request, and the flag is how it is asked to. With it on, a context variable set
101
+ before the server started is not seen by a request; pass such a value through the
102
+ application's state.
103
+
94
104
  ```console
95
105
  $ curl -i localhost:8000/books/0262510871
96
106
  HTTP/1.1 200 OK
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-http-kernel"
3
- version = "6.6.0"
3
+ version = "6.8.0"
4
4
  description = "Requests turned into responses through events: a request lifecycle for FastAPI applications on the xtr kernel."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -25,8 +25,8 @@ classifiers = [
25
25
  "Typing :: Typed",
26
26
  ]
27
27
  dependencies = [
28
- "fastapi>=0.121.3",
29
- "starlette>=0.40",
28
+ "fastapi>=0.143.1",
29
+ "starlette>=1.3.1",
30
30
  "xtr-dependency-injection>=6.0,<7",
31
31
  "xtr-event-dispatcher>=6.0,<7",
32
32
  "xtr-event-dispatcher-contracts>=6.0,<7",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-http-kernel"
3
- version = "6.6.0"
3
+ version = "6.8.0"
4
4
  description = "Requests turned into responses through events: a request lifecycle for FastAPI applications on the xtr kernel."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -23,9 +23,16 @@ classifiers = [
23
23
  # takes the container layer and the web framework outright rather than behind
24
24
  # an extra: there is nothing left of it once either is gone.
25
25
  dependencies = [
26
- "fastapi>=0.121.3",
27
- # Imported directly — requests, responses, middleware — not only through fastapi.
28
- "starlette>=0.40",
26
+ # 0.143.1 is the first release whose effective view of an application's routes
27
+ # gives an included WebSocket route its prefixed path; the router listing and
28
+ # the route conflict check read that view.
29
+ "fastapi>=0.143.1",
30
+ # Imported directly — requests, responses, middleware — not only through fastapi,
31
+ # which asks for far less than this package needs. The bridge's response
32
+ # builds on the 1.x response, and 1.3.1 is the first release that enforces
33
+ # the limits of a urlencoded form, which every request read as a message
34
+ # goes through (GHSA-82w8-qh3p-5jfq).
35
+ "starlette>=1.3.1",
29
36
  "xtr-dependency-injection>=6.0,<7",
30
37
  "xtr-event-dispatcher>=6.0,<7",
31
38
  "xtr-event-dispatcher-contracts>=6.0,<7",
@@ -59,9 +59,15 @@ the environment are read at that moment. Then it wraps two seams:
59
59
  afresh. Each applies test overrides, boots, attaches the container so the route markers
60
60
  resolve, runs the app's own lifespan inside, then detaches and shuts down.
61
61
  - **One middleware.** Fetches the kernel's `MiddlewareStack` once per life and runs every
62
- request through it, inside the request scope scoped services live in.
62
+ request through it, inside the request scope scoped services live in. The scope is opened on
63
+ the request's own connection, so a request never reads another's — whatever context the
64
+ server started its task from.
63
65
 
64
- Serve it with any ASGI server: `uvicorn app.web:app`.
66
+ Serve it with any ASGI server: `uvicorn --reset-contextvars app.web:app` (uvicorn 0.45 or
67
+ later). The flag starts each request in a context of its own; without it a request on a
68
+ kept-alive connection can start with the context variables an earlier one set. The kernel's own
69
+ per-request state is safe either way; the application's, and that of the libraries it uses, is
70
+ only safe with it.
65
71
 
66
72
  ## Routes
67
73
 
@@ -412,8 +418,8 @@ The routing errors import from `xtr_http_kernel.routing`, under `RoutingError` (
412
418
  endpoints' `Injected[...]` parameters.
413
419
  - Do not use `Depends` to reach a container service. Use `Injected[T]` or `Target("name")`, so
414
420
  the service stays out of the OpenAPI schema.
415
- - Do not call `attach`, `detach`, `request_scope`, `provider` or `current_connection` from
416
- `xtr_dependency_injection.integration.fastapi`. They are what `setup` is built on; an
421
+ - Do not call `attach`, `detach`, `request_scope`, `provider`, `current_connection` or
422
+ `connection_of` from `xtr_dependency_injection.integration.fastapi`. They are what `setup` is built on; an
417
423
  application calls `setup` and nothing lower. To reach the request being served, take the
418
424
  framework's own `request: Request` in a route, or `Injected[ServerRequestInterface]` in a
419
425
  route — a plain `ServerRequestInterface` parameter in a service — for the request as a
@@ -4,7 +4,9 @@ Plain ASGI on purpose — no base class dispatch, no response buffering — so
4
4
  the scope opens before anything downstream runs and closes only when the
5
5
  downstream returned, which is after the response's last chunk left. The
6
6
  scope opener arrives through the constructor rather than an import, so this
7
- module stays free of the container layer.
7
+ module stays free of the container layer. It is handed the connection as
8
+ well as the application: a request's scope is opened on its own connection,
9
+ which is the one thing a server hands a request that is no other request's.
8
10
  """
9
11
 
10
12
  from __future__ import annotations
@@ -22,7 +24,7 @@ if TYPE_CHECKING:
22
24
 
23
25
  from .middleware_stack import MiddlewareStack
24
26
 
25
- ScopeOpener = Callable[[Starlette], AbstractAsyncContextManager[None]]
27
+ ScopeOpener = Callable[[Starlette, Scope], AbstractAsyncContextManager[None]]
26
28
 
27
29
  __all__ = ["KernelMiddleware"]
28
30
 
@@ -39,6 +41,11 @@ class KernelMiddleware:
39
41
  scoped service lives until the response has been sent. The scope closes
40
42
  on every path, a failing downstream included; the failure still
41
43
  propagates. The ``lifespan`` connection passes through untouched.
44
+
45
+ Every connection opens a scope of its own, on the connection itself. A
46
+ server may start a request's task from the context of an earlier request
47
+ on the same socket, so nothing is taken from what the context carries:
48
+ what the request is resolved against is what was opened here, for it.
42
49
  """
43
50
 
44
51
  __slots__ = ("_app", "_chain", "_open_scope", "_stack")
@@ -57,7 +64,7 @@ class KernelMiddleware:
57
64
  return
58
65
  application = cast("Starlette", scope["app"])
59
66
  chain = self._composed(application)
60
- async with self._open_scope(application):
67
+ async with self._open_scope(application, scope):
61
68
  await chain(scope, receive, send)
62
69
 
63
70
  def _composed(self, application: Starlette) -> ASGIApp:
@@ -1,15 +1,9 @@
1
- """One view of an application's routes, whichever way the framework hands them over.
2
-
3
- Newer releases keep a router included under a prefix as a wrapper around that
4
- router rather than as the routes it holds, and offer the effective view of
5
- every route — prefixes applied — through ``iter_route_contexts``. Older ones
6
- put each route in the list directly, already effective. This module is the
7
- only place that difference lives.
8
-
9
- A release that grew the wrapper before it grew the view of one lists an
10
- included router as the single opaque route the application holds: there is no
11
- supported way in, so the row names the wrapper for what it is rather than
12
- inventing a path for it.
1
+ """One view of an application's routes, every prefix applied.
2
+
3
+ The framework keeps a router included under a prefix as a wrapper around that
4
+ router rather than as the routes it holds, and offers the effective view of
5
+ every route — prefixes applied — through ``iter_route_contexts``. This module
6
+ is the only place that reads it.
13
7
  """
14
8
 
15
9
  from __future__ import annotations
@@ -17,11 +11,10 @@ from __future__ import annotations
17
11
  from dataclasses import dataclass
18
12
  from typing import TYPE_CHECKING, Protocol, cast, final
19
13
 
20
- from fastapi import routing as fastapi_routing
21
- from starlette.routing import Host, Mount, Route, WebSocketRoute
14
+ from fastapi.routing import iter_route_contexts
22
15
 
23
16
  if TYPE_CHECKING:
24
- from collections.abc import Callable, Iterable, Sequence
17
+ from collections.abc import Sequence
25
18
 
26
19
  from fastapi.routing import RouteContext
27
20
  from starlette.routing import BaseRoute, Match
@@ -53,7 +46,7 @@ class RouteView:
53
46
  endpoint: What it hands the request to, ``None`` when it hands it to
54
47
  another application instead.
55
48
  matcher: What answers :meth:`matches` — the framework's own view of
56
- the route, or the route itself.
49
+ the route.
57
50
  """
58
51
 
59
52
  route: BaseRoute
@@ -74,18 +67,8 @@ class RouteView:
74
67
 
75
68
 
76
69
  def route_contexts(routes: Sequence[BaseRoute]) -> Sequence[RouteView]:
77
- """Read every route of an application, prefixes applied.
78
-
79
- A release offering the effective view of each route is asked for it; the
80
- rest hand their routes over already effective.
81
- """
82
- effective = cast(
83
- "Callable[[Sequence[BaseRoute]], Iterable[RouteContext]] | None",
84
- getattr(fastapi_routing, "iter_route_contexts", None),
85
- )
86
- if effective is None:
87
- return [_of_route(route) for route in routes]
88
- return [_of_context(context) for context in effective(routes)]
70
+ """Read every route of an application, prefixes applied."""
71
+ return [_of_context(context) for context in iter_route_contexts(routes)]
89
72
 
90
73
 
91
74
  def _of_context(context: RouteContext) -> RouteView:
@@ -98,16 +81,3 @@ def _of_context(context: RouteContext) -> RouteView:
98
81
  endpoint=context.endpoint,
99
82
  matcher=context,
100
83
  )
101
-
102
-
103
- def _of_route(route: BaseRoute) -> RouteView:
104
- """Read a route a release hands over already effective.
105
-
106
- Each line below names the kinds of route that can answer that much; a kind
107
- that answers none of it is left to be named by itself.
108
- """
109
- methods = route.methods if isinstance(route, Route) else None
110
- endpoint = route.endpoint if isinstance(route, (Route, WebSocketRoute)) else None
111
- path = route.path if isinstance(route, (Mount, Route, WebSocketRoute)) else None
112
- name = route.name if isinstance(route, (Host, Mount, Route, WebSocketRoute)) else None
113
- return RouteView(route, path, name, methods, endpoint, route)
@@ -20,11 +20,10 @@ from starlette.datastructures import FormData
20
20
  from starlette.requests import Request
21
21
  from typing_extensions import override
22
22
 
23
- # Read at runtime: materialisation prefers the framework's own connection,
24
- # whose caches spare a second reading of the wire, and the refusal when no
25
- # request is being served is what tells this connection to read its own.
26
- from xtr_dependency_injection.exception import FastapiIntegrationError
27
- from xtr_dependency_injection.integration.fastapi import current_connection
23
+ # Read at runtime: materialisation prefers the framework's own request,
24
+ # whose caches spare a second reading of the wire, and looks for it on this
25
+ # connection's own scope.
26
+ from xtr_dependency_injection.integration.fastapi import connection_of
28
27
  from xtr_http_message import RequestSource, ServerRequest
29
28
 
30
29
  if TYPE_CHECKING:
@@ -257,12 +256,15 @@ class ServedConnection(RequestSource):
257
256
  request object, so reading through that one shares those caches;
258
257
  before routing there is none, and this connection's own request
259
258
  reads the wire.
259
+
260
+ The framework's request is looked for on this connection's own
261
+ scope, never in the calling context: a context may carry another
262
+ request's — a server can start a request's task from an earlier
263
+ one's — and reading through that one would hand this request a
264
+ body and a form that are not its own.
260
265
  """
261
- try:
262
- connection = current_connection()
263
- except FastapiIntegrationError:
264
- return self._request
265
- return connection if isinstance(connection, Request) else self._request
266
+ published = connection_of(self._request.scope)
267
+ return published if isinstance(published, Request) else self._request
266
268
 
267
269
  async def _raw_body(self, request: Request) -> bytes:
268
270
  """Return the raw body of ``request``, empty where a form already took the wire.
File without changes