Why don't I see any cookie sent for 2.x ? #3969
-
I just upgraded my socket.io from 2.3 to 4.1. After reading migrating guide I noticed it says "No more cookie by default" but the problem is I didn't see cookie sent even for 2.3. Why is that ? I am using transports: ['websocket'] only. Is this the reason ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, there's no cookie when using only WebSocket, in all versions. It wouldn't make sense to send a cookie, since there is a single HTTP request (the WebSocket connection) for the whole session, and the cookie is not used upon reconnection. You can add additional headers in the response though: io.engine.on("initial_headers", (headers, req) => {
headers["test"] = "123";
headers["set-cookie"] = "mycookie=456";
}); Reference: https://socket.io/docs/v4/server-instance/#Server-engine |
Beta Was this translation helpful? Give feedback.
Yes, there's no cookie when using only WebSocket, in all versions.
It wouldn't make sense to send a cookie, since there is a single HTTP request (the WebSocket connection) for the whole session, and the cookie is not used upon reconnection.
You can add additional headers in the response though:
Reference: https://socket.io/docs/v4/server-instance/#Server-engine