-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Sanic Request
to WebSocket Request
in websocket_handshake
#2858
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2858 +/- ##
=============================================
+ Coverage 88.188% 88.254% +0.066%
=============================================
Files 93 93
Lines 7298 7305 +7
Branches 1254 1254
=============================================
+ Hits 6436 6447 +11
+ Misses 601 599 -2
+ Partials 261 259 -2 ☔ View full report in Codecov by Sentry. |
2343a4a
to
b4fb3b2
Compare
4f989fa
to
a8051f5
Compare
Echo my thought in the issue thread: Another way I am thinking about is to build WebSocket request object instead of Sanic Request in http protocol if the WebSocket handler is being used. This seems to come with a better performance, but much more complicated and might not be very feasible since we assume |
I do not think this is something we can change. Not only do we make this assumption, it is a contract we've established and changing that would break a lot of apps. |
Description
This PR is a (potentially naive) solution to fix an issue that missed WebSocket Upgrade request header during a WebSocket handshaking process causing 500 server error being returned.
After debugging, I found that the error stems from Sanic's Request object being passed into
ws_proto.accept(...)
method, which expects arequest
to be a WebSocket Request object. The issue is occurred when thewebsockets
package is trying to assign an_exception
value to the request object, resulting the attribute not existent error will be raised, which causes a 500 server error.My solution is to convert Sanic Request object to be a WebSocket Request object in
websocket_handshake
method. I feel like this is a naive solution and am stilling digging into how a WebSocket requests is processed in Sanic's code, and I am also working on test cases.May I have some feedback and comments?
Related issue
closes #2743
Code snippets for reproducing the issue
server
client