This is definitely a wart in the API, but not one that we're likely to fix in v0.8. It may require rethinking a few things, and we are not prepared to make major changes to the HTTP layer right now.
Can you write up the feature request as an issue? Let's get it on the list for v0.9. 2012/3/29 Stéphan Kochen <step...@angrybytes.com>: > Here's the example from before as a test case: > > https://github.com/stephank/node/commit/0339fc0 > > I went a step further, and experimented with providing a response object > for upgrade and CONNECT requests, also queuing them properly. This is on > a branch at: > > https://github.com/stephank/node/compare/upgrade-response > > Notably: > > - The `upgrade` and `connect` event listeners have the same signature > as regular `request` events, namely `(req, res)`. > > - The response can be treated like any other, and `res.end` will treat > it as if with `Connection: close`. (Ie. `shouldKeepAlive = false`). > > - To successfully upgrade, call `res.switchProtocols`, rather than > `res.end`, which takes a callback with the familiar `(sock, head)`. > > Example: > > var http = require('http'); > > var server = http.createServer(); > > server.on('request', function(req, res) { > res.writeHead(200, {'Content-Type': 'text/plain'}); > res.end('Hello World\n'); > }); > > server.on('upgrade', function(req, res) { > res.writeHead(101, { > 'Upgrade': 'dummy', > 'Connection': 'Upgrade' > }); > res.switchProtocols(function(sock, head) { > /* ... */ > }); > }); > > server.listen(3000);