Repository navigation
Is there a way to get socket.io client upgrade response header and status code? #5328
Is there a way to get these response messages when using the socket.io client?
|
Replies: 1 comment
|
For the browser client in your screenshot, the WebSocket HTTP response headers and the If you want to know when the transport becomes WebSocket, use the Engine.IO transport events exposed by the client: socket.on('connect', () => {
const engine = socket.io.engine;
console.log('Current transport:', engine.transport.name);
engine.on('upgrade', transport => {
console.log('Upgraded to:', transport.name);
});
});This reports the transport, not the HTTP status or headers. See the client Socket instance documentation. If you need application information from the server, send a normal authenticated Socket.IO event with the specific non-sensitive fields you need. That is application data rather than a copy of the upgrade response. If the connection fails before Socket.IO connects, inspect DevTools and the proxy/server logs; namespace middleware can provide structured The Node.js client has different capabilities, so the answer depends on whether you mean the browser shown in the screenshot or a Node process. The browser restriction follows the WebSocket interface, and Socket.IO documents related browser header restrictions in client options. |

For the browser client in your screenshot, the WebSocket HTTP response headers and the
101 Switching Protocolsstatus are visible in DevTools, but the browser WebSocket API does not expose them to application JavaScript. Socket.IO cannot make those raw upgrade headers available through its browser client.If you want to know when the transport becomes WebSocket, use the Engine.IO transport events exposed by the client:
This reports the transport, not the HTTP status or he…