Using Cookies with 'websocket' transport #936
-
I know this has been asked a thousand times, and I've tried my best to avoid asking but I just can't piece together enough information together to get this working. I'm using python-socketio for my server, and the javascript socketio library for my client. I've set the cookie parameter of AsyncServer to a dictionary.
Then when going back to 'websocket', the cookie is sent to the server (I can see it in the environ printout). Does the 'websocket' transport support setting cookies?
As the SID passed to the server on connect is the SID from the previous session, it seems that it could be used to tie a new session to the last. But that then flows into my next point
Note the difference between my custom printed "sid=..." and the sid in the query string. It seems I need to add custom events for setting/querying the cookies from the client rather than trying to make the above work? As an aside, it seems chrome doesn't show websocket cookies? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You are trying to do something that cannot be done. Cookies can only be set when there is an HTTP response. Websocket doesn't have that, so it has no way to deliver a cookie to the browser. |
Beta Was this translation helpful? Give feedback.
-
In a WebSocket handshake, you can set a cookie without any problems. If you need to do this later, then you either need to make additional HTTP/GET requests to set the cookie from the server, or set the cookie via JS/WebSocket
|
Beta Was this translation helpful? Give feedback.
You are trying to do something that cannot be done. Cookies can only be set when there is an HTTP response. Websocket doesn't have that, so it has no way to deliver a cookie to the browser.