latch-asgi 1.0.6.dev0__tar.gz → 1.0.6.dev1__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.
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/PKG-INFO +1 -1
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/server.py +15 -7
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/pyproject.toml +1 -1
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/COPYING +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/README.md +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/__init__.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/asgi_iface.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/auth.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/config.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/context/__init__.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/context/common.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/context/http.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/context/websocket.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/datadog_propagator.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/framework/__init__.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/framework/common.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/framework/http.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/framework/websocket.py +0 -0
- {latch_asgi-1.0.6.dev0 → latch_asgi-1.0.6.dev1}/latch_asgi/py.typed +0 -0
|
@@ -222,6 +222,13 @@ class LatchASGIServer:
|
|
|
222
222
|
s.set_attribute("http.route", scope["path"])
|
|
223
223
|
|
|
224
224
|
close_reason: str | None = None
|
|
225
|
+
close_already_sent: bool = False
|
|
226
|
+
|
|
227
|
+
async def send_tracking(e):
|
|
228
|
+
nonlocal close_already_sent
|
|
229
|
+
if isinstance(e, dict) and e.get("type") == "websocket.close":
|
|
230
|
+
close_already_sent = True
|
|
231
|
+
await send(e)
|
|
225
232
|
try:
|
|
226
233
|
try:
|
|
227
234
|
msg = await receive()
|
|
@@ -230,7 +237,7 @@ class LatchASGIServer:
|
|
|
230
237
|
"ASGI protocol violation: missing websocket.connect event"
|
|
231
238
|
)
|
|
232
239
|
|
|
233
|
-
ctx = websocket.Context(scope, receive,
|
|
240
|
+
ctx = websocket.Context(scope, receive, send_tracking)
|
|
234
241
|
close_reason = await handler(ctx)
|
|
235
242
|
except WebsocketErrorResponse:
|
|
236
243
|
raise
|
|
@@ -241,7 +248,7 @@ class LatchASGIServer:
|
|
|
241
248
|
raise WebsocketInternalServerError("Internal Error") from e
|
|
242
249
|
except WebsocketErrorResponse as e:
|
|
243
250
|
await close_connection(
|
|
244
|
-
|
|
251
|
+
send_tracking, status=e.status, reason=orjson.dumps({"error": e.data}).decode()
|
|
245
252
|
)
|
|
246
253
|
|
|
247
254
|
if e.status != WebsocketStatus.server_error:
|
|
@@ -249,12 +256,13 @@ class LatchASGIServer:
|
|
|
249
256
|
|
|
250
257
|
raise
|
|
251
258
|
else:
|
|
252
|
-
if
|
|
253
|
-
close_reason
|
|
259
|
+
if not close_already_sent:
|
|
260
|
+
if close_reason is None:
|
|
261
|
+
close_reason = "Session complete"
|
|
254
262
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
await close_connection(
|
|
264
|
+
send_tracking, status=WebsocketStatus.normal, reason=close_reason
|
|
265
|
+
)
|
|
258
266
|
|
|
259
267
|
async def scope_http(
|
|
260
268
|
self: Self,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|