Repository navigation
Does socket.io supports passing custom cookies with socket.io-client? #5329
Replies: 1 comment
|
Because your client is an HTML page, the browser controls the Instead, have an HTTP endpoint set a real browser cookie for the public proxy/socket hostname before connecting. The browser will attach eligible cookies to requests to that host, including the WebSocket upgrade. A cookie scoped to some different backend hostname will not be sent to your proxy just because the proxy forwards requests there. For the default polling-then-upgrade flow across origins: const socket = io('https://socket.example.com', {
withCredentials: true,
});Configure the Socket.IO server's CORS response with your actual frontend origin and Then your existing proxy upgrade handler can read the incoming header before forwarding: server.on('upgrade', (req, socket, head) => {
const cookieHeader = req.headers.cookie;
// Parse cookieHeader here if the proxy needs a particular cookie.
proxy.ws(req, socket, head);
});Node exposes incoming header names in lowercase, hence A Node.js |
Uh oh!
There was an error while loading. Please reload this page.
I need help with cookie handling between the socket.io-client and node.js server
Current Setup:
What I'm trying to achieve:
I need to access cookies that are set in the Socket.IO client during the WebSocket handshake on my proxy server side.
Socket.io client initialization
How to access this cookie in proxy server's upgrade event?
proxy.js
Let me know if you have any other suggestions for passing cookies from socket.io-client to server, I am open for ideas
All reactions