Skip to content
This repository

Allow access to Cookie/Session middleware on 'upgrade' events #342

Sironfoot opened this Issue · 3 comments

4 participants

Dominic Pettifer Jonathan Ong Thomas Muldowney Erin
Dominic Pettifer

I want to access cookies and session objects during an upgrade event. eg:

app.on('upgrade', function(req, socket, head) {
    var someValue = req.session.someValue; // Doesn't work

Cookie and Session middleware is hooked up properly and accessible from app.get/post/put/delete methods, just not from special events such as 'upgrade' even though the Connect session cookie token is available in the raw HTTP request headers eg.

    var connectCookie = req.headers['cookie'];

FYI: an 'upgrade' event is fired on a WebSocket handshake. During the handshake it would be ideal to get hold of the logged in user (stored in the current session). Also WebSocket frameworks for node.js as such rely on the 'upgrade' event, hence why I believe this feature would be desirable for anyone building web sites that use WebSockets.

Thomas Muldowney


This makes websockets, within an overall site context, extremely difficult.


Bump for this.
I'm having to use a custom cookie parser as a workaround since this isn't available.
It would probably just involve suppressing the original upgrade event, creating a custom one that is sent through a certain config chain before being sent to the upgrade handler.

Jonathan Ong

connect isn't going to wrap around http servers. create a separate app to handle http.createServer().on('upgrade', app).

Jonathan Ong jonathanong closed this
Something went wrong with that request. Please try again.