TrustedHostMiddleware raises RuntimeError on sending response to websocket #2225
Answered
by
Kludex
Budek
asked this question in
Potential Issue
-
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.trustedhost import TrustedHostMiddleware
from starlette.routing import WebSocketRoute
async def app(websocket):
await websocket.accept()
await websocket.send_text("Hello, world!")
await websocket.close()
routes = [
WebSocketRoute("/ws", app),
]
middleware = [
Middleware(
TrustedHostMiddleware,
allowed_hosts=["example.com", "*.example.com"],
),
]
app = Starlette(routes=routes, middleware=middleware) Using the provided example code and making a request websocket request without header Host or with invalid header i get the following exception.
|
Beta Was this translation helpful? Give feedback.
Answered by
Kludex
Jan 14, 2024
Replies: 1 comment
-
This should be a bug. Thanks for reporting it.
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be a bug. Thanks for reporting it.