[litestarV2] Websockets: best way to accept() custom headers with the new WebsocketListener
class
#1552
-
Hello, I'm wondering if it's possible (or even relevant) to be using the The "old" way of doing this would be, IIRC, : from starlite import websocket, WebSocket
from starlite.exceptions import WebSocketDisconnect
@websocket("/")
async def handler(socket: WebSocket) -> str:
# for instance, here, sending a cookie to be set on the client
await socket.accept({'Cookie': 'custom-cookie'})
while True:
try:
data = await socket.receive_text()
await socket.send_text(data)
except WebSocketDisconnect:
break In the new Is there any way to do this? Is it even a good idea to use |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Hi, thanks for opening this. You are indeed correct that there currently is not a way to do what you want. I actually considered this but decided to address this at a later point. I guess that point is now. I think the best way to handle this is to simply add an Alternatively, we could change the behaviour of @peterschutt wdyt? |
Beta Was this translation helpful? Give feedback.
-
Something like this? class websocket_listener(WebsocketRouteHandler):
def __init__(
...,
acceptor: Callable[[WebSocket], Coroutine[Any, Any, None]] = WebSocket.accept,
...,
) -> None:
... |
Beta Was this translation helpful? Give feedback.
-
why not inject a helper called |
Beta Was this translation helpful? Give feedback.
-
Created #1571 |
Beta Was this translation helpful? Give feedback.
Created #1571