Skip to content

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

Closed
Sironfoot opened this Issue Aug 11, 2011 · 3 comments

4 participants

@Sironfoot

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.

app.on('upgrade', function(req, socket, head) {
    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 https://github.com/Worlize/WebSocket-Node rely on the 'upgrade' event, hence why I believe this feature would be desirable for anyone building web sites that use WebSockets.

@temas
temas commented Sep 20, 2011

+1

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

@download13

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.

@jonathanong

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.