python-fasthtml 0.14.22__tar.gz → 0.14.23__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.
- {python_fasthtml-0.14.22/python_fasthtml.egg-info → python_fasthtml-0.14.23}/PKG-INFO +1 -1
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/__init__.py +1 -1
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/proxy.py +28 -23
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23/python_fasthtml.egg-info}/PKG-INFO +1 -1
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/tests/test_fh.py +4 -1
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/CONTRIBUTING.md +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/LICENSE +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/MANIFEST.in +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/README.md +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/_modidx.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/authmw.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/basics.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/cli.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/common.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/components.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/components.pyi +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/core.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/core.pyi +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/fastapp.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/ft.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/js.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/jupyter.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/katex.js +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/live_reload.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/oauth.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/pico.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/starlette.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/stripe_otp.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/svg.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/toaster.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/xtend.py +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/fasthtml/xtend.pyi +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/pyproject.toml +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/python_fasthtml.egg-info/SOURCES.txt +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/python_fasthtml.egg-info/dependency_links.txt +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/python_fasthtml.egg-info/entry_points.txt +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/python_fasthtml.egg-info/requires.txt +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/python_fasthtml.egg-info/top_level.txt +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/setup.cfg +0 -0
- {python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/tests/test_proxy.py +0 -0
|
@@ -6,7 +6,7 @@ Register proxy handlers with Starlette's `Route` and `WebSocketRoute`. FastHTML'
|
|
|
6
6
|
|
|
7
7
|
Connection-nominated headers and explicitly excluded names are removed. Repeated end-to-end values remain separate, with lowercase names.
|
|
8
8
|
|
|
9
|
-
`proxy_websocket` connects upstream before accepting the caller. It forwards the selected subprotocol and relays text and binary frames. Either peer disconnecting cancels the other forwarding task and closes the upstream connection. Supply a complete URL, including any query parameters.
|
|
9
|
+
`proxy_websocket` connects upstream before accepting the caller. Upstream HTTP 401, 403 and 404 responses accept and close the caller with code 1008. It forwards the selected subprotocol and relays text and binary frames. Either peer disconnecting cancels the other forwarding task and closes the upstream connection. Supply a complete URL, including any query parameters.
|
|
10
10
|
|
|
11
11
|
The relay reads raw ASGI events from `receive()`. A `websocket.receive` event carries `text` or `bytes`. A `websocket.disconnect` event carries a close `code`. `receive_text()` and `receive_bytes()` extract one data field instead.
|
|
12
12
|
|
|
@@ -75,26 +75,31 @@ async def proxy_websocket(
|
|
|
75
75
|
headers=None, # Additional upstream handshake headers
|
|
76
76
|
):
|
|
77
77
|
"Relay text and binary frames until either peer disconnects."
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
async
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
78
|
+
try:
|
|
79
|
+
async with websockets.connect(url, additional_headers=headers,
|
|
80
|
+
subprotocols=websocket.scope['subprotocols'] or None, max_size=None) as target:
|
|
81
|
+
await websocket.accept(subprotocol=target.subprotocol)
|
|
82
|
+
async def to_target():
|
|
83
|
+
while True:
|
|
84
|
+
message = await websocket.receive()
|
|
85
|
+
if message['type']=='websocket.disconnect': return
|
|
86
|
+
await target.send(message['text'] if 'text' in message else message['bytes'])
|
|
87
|
+
async def to_client():
|
|
88
|
+
async for message in target:
|
|
89
|
+
if isinstance(message, str): await websocket.send_text(message)
|
|
90
|
+
else: await websocket.send_bytes(message)
|
|
91
|
+
tasks = [asyncio.create_task(to_target()), asyncio.create_task(to_client())]
|
|
92
|
+
try:
|
|
93
|
+
done,_ = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
|
94
|
+
for task in done: task.result()
|
|
95
|
+
finally:
|
|
96
|
+
for task in tasks: task.cancel()
|
|
97
|
+
await asyncio.gather(*tasks, return_exceptions=True)
|
|
98
|
+
if websocket.client_state.name!='DISCONNECTED':
|
|
99
|
+
code = target.close_code if target.close_code not in (None, 1005, 1006, 1015) else 1011
|
|
100
|
+
await websocket.close(code=code, reason=target.close_reason or '')
|
|
101
|
+
except websockets.exceptions.InvalidStatus as e:
|
|
102
|
+
if e.response.status_code not in (401, 403, 404): raise
|
|
103
|
+
await websocket.accept()
|
|
104
|
+
await websocket.close(code=1008, reason=f'Upstream refused connection ({e.response.status_code})')
|
|
100
105
|
|
|
@@ -69,6 +69,7 @@ async def echo_http(request):
|
|
|
69
69
|
return response
|
|
70
70
|
|
|
71
71
|
async def echo_ws(ws):
|
|
72
|
+
if status := ws.query_params.get('deny'): return await ws.send_denial_response(Response(status_code=int(status)))
|
|
72
73
|
await ws.accept(subprotocol='echo')
|
|
73
74
|
await ws.send_text(await ws.receive_text())
|
|
74
75
|
await ws.send_bytes(await ws.receive_bytes())
|
|
@@ -79,7 +80,7 @@ def test_proxy():
|
|
|
79
80
|
with running_server(upstream) as url:
|
|
80
81
|
async def forward_http(request):
|
|
81
82
|
return ProxyResponse(request, url, headers=proxy_headers(request.headers, exclude=(b'authorization',)))
|
|
82
|
-
async def forward_ws(ws): await proxy_websocket(ws, url.replace('http', 'ws')+'/ws')
|
|
83
|
+
async def forward_ws(ws): await proxy_websocket(ws, url.replace('http', 'ws')+'/ws?'+ws.url.query)
|
|
83
84
|
app = Starlette(routes=[Route('/', forward_http, methods=['PATCH']), WebSocketRoute('/ws', forward_ws)])
|
|
84
85
|
with TestClient(app) as proxy:
|
|
85
86
|
body = b'["a", {"b":2}]'
|
|
@@ -97,3 +98,5 @@ def test_proxy():
|
|
|
97
98
|
ws.send_bytes(b'\x00bytes')
|
|
98
99
|
assert ws.receive_bytes() == b'\x00bytes'
|
|
99
100
|
assert ws.receive()['code'] == 1000
|
|
101
|
+
for status in (401, 403, 404):
|
|
102
|
+
with proxy.websocket_connect(f'/ws?deny={status}') as ws: assert ws.receive()['code'] == 1008
|
|
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
|
|
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
|
{python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/python_fasthtml.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{python_fasthtml-0.14.22 → python_fasthtml-0.14.23}/python_fasthtml.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|