-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
A proposal for handling upgrade requests. #506
Conversation
Any thoughts on this? In the meantime, I have a branch of sockjs-node with some middleware sugar that upstream is willing to accept. There's an example of mounting SockJS as middleware. (Compare to the non-Connect example.) Something like ws would be mountable with a dummy HTTP server, or using the
Though hopefully, upstream ws will also accept some sugar for this (along the lines of |
I don't really see the big difference between this and simply listening for the |
Some of the stock middleware in Connect is potentially useful, but would of course need to be adapted to handle upgrade requests. I'm thinking of: vhost, query, cookie, basicAuth, and logger. For me, just the routing would already be very useful. |
Reusing existing middleware is definitely something to investigate here. I started out by modifying the logger middleware. It'll treat an upgrade request as if with the
The stuff doesn't have tests, but then logger doesn't have any tests at all. What's interesting here is that a normal HTTP response will always follow (usually (Probably also the reason why Node's default behavior, without an |
Here's an experiment in adding a response object to Upgrade requests, right in Node's This would also allow middleware to add headers (e.g. cookie), and more easily abort the request without having to write the HTTP response out manually (e.g. basicAuth). FWIW, I only just noticed that Node also has a |
It was worth a shot, I think, but it looks like API changes to Node's So, some options:
The
But the beauty is that for middleware that simply wants to amend (logger) or cancel (basicAuth) the request, nothing much changes but (It's worth mentioning that on this branch, logger is also able to properly log the HTTP response, ie. no 'immediate'.) |
I went through the stock middleware, and most of them will plain work if given a ServerResponse object. On branch
I also have a version of Middleware that doesn't make sense:
edit: Middleware that uses the request body doesn't make sense either, of course. Reverted those changes. |
What's the status on this? It would be great if websocket libraries could be integrated with connect. |
The Node.js pull-request on this has been reopened, but the plan there is to reconsider the idea for Node.js 0.9. Nothing much here on the Connect front, unfortunately. |
@stephank when you say "nothing much here on the connect front" does that mean that there is nothing that you guys can do to get around this? Are you blocked by the update/pull request in Node before you can do anything? I'm in need of this feature because of an issue that I have in socket.io socketio/socket.io#879 obviously all connected ;) |
Simply meant to say that there's no update. I have an API proposal that can be implemented either at the Node level, or the Connect level. Node will consider this for 0.9, I've yet to hear from any of the maintainers here. But I think it's unlikely that anything will happen until Node makes a decision, considering the risk that doing anything now in Connect will possibly result in APIs between Node and Connect diverging, for example if Node decides on a slightly different API later on. |
reopen when those node issues are closed |
This is a working implementation, with tests, for handling upgrade requests with connect middleware.
The basic premise is to reuse the existing middleware stack, but have a separate handler for these requests. With this pull, things work as follows:
Middleware without an upgrade handler is skipped. If no upgrade handler is found for an upgrade request, the request socket is closed. (This follows
http.Server
behavior, without anupgrade
event listener.)Possible issues:
upgrade
attribute will do funky stuff when an upgrade request is sent there.upgrade
events on thehttp.Server
themselves will fail, because Connect is always the first listener, and will close the socket.