WebSocket doesn't support essential binders
See original GitHub issueRight now, you can’t use binders like FromQuery
, FromHeader
, and FromCookie
with WebSocket
, as it doesn’t provide the required properties: headers
, query
, cookies
. Therefore, for example, you can’t guard the WebSocket endpoint with some sort of authorization. That seems pretty important to me.
I investigated a bit into code and found out that both Request
and Response
inherit from the Message
class, which implements headers. Request
and Response
have a different approach to handling cookies, and only the Request
class handles query parameters. I did not dig deep, though.
The question is - which way is best to add support for all these binders for WebSocket?
- Implement the same properties in this class, but this would duplicate the code. Easy to do, but probably better to avoid.
- Find ways to extract the needed functionality into mixin classes - like HeadersMixin, QueryMixin, CookiesMixin. Inject them as needed. It will probably require porting WebSocket into Cython.
- Anything else?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
WebSockets With Spring, Part 2 - Medium
Some load balancers do not support WebSocket. In this case, it is necessary to exclude WebSocket from the list of available SockJS transports....
Read more >websocket can´t reach local network client service
So it seems that the packets reach my laptop but not the service. Could it be that the server is binding to a...
Read more >client can not connect to websocket server! #1690 - GitHub
I use the minimal-ws-client-ping and modify some necessary variables, compile it and try to connect to my own websocket server which was not...
Read more >WebSockets Crash Course - Handshake, Use-cases, Pros ...
WebSockets example (Server/Client) - WebServers Pros and Cons Pros 1. ... ( alternatives ) It is important to note that WebSockets is not...
Read more >Enabling User Feedback with WebSockets on RabbitMQ and ...
If the server does not support any, then the connection is aborted. Client may send a list of protocol extensions in Sec-WebSocket-Extensions ....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t think this is an issue. The initial WebSocket request is by definition GET, so it cannot have any body. It’s arguably the same with requests using methods that don’t allow bodies like GET, HEAD, OPTIONS, etc. - they still expose methods to read the content even though they cannot have any (or they could have but the server ignores it anyway). And I know developers who got confused because they tried to read the payload from requests done over GET, but most web frameworks simply ignore the payload and do nothing about it (on this topic).
That particular thing with
incoming
look crazy, I agree, but it’s one of the things I spent the most time on 😄 When I wrote it, I made many performance tests and verified it was resulting in better performance. It can be made cleaner if we “kill” the HTTP Client implementation in BlackSheep and modifyRequest/Response
to work only in one direction - this is something I’ve been considering since a long time https://github.com/Neoteroi/BlackSheep/discussions/106.To me, it seems like right now we do exactly what the ASGI spec tells us to do.
https://asgi.readthedocs.io/en/latest/specs/www.html#close-send-event
Maybe I get you wrong and you meant some other case?