Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 921 Bytes

README.md

File metadata and controls

34 lines (25 loc) · 921 Bytes

upgradeEx Build Status

A stand-alone version of this Node.js PR, this module gives you a ServerResponse in upgrade and connect events.

var http = require('http');
var upgradeEx = require('upgrade-ex');

var server = http.createServer();
upgradeEx.addEvents(server);

server.on('upgradeEx', function(req, res) {
  res.writeHead(101, {
    'Connection': 'Upgrade',
    'Upgrade': 'Echo'
  });

  res.switchProtocols(function(sock) {
    sock.on('readable', function() {
      var chunk = sock.read();
      sock.write(chunk);
    });
  });
});

Alternatively, without addEvents():

server.on('upgrade', upgradeEx.wrap(function(req, res) {
  /* ... */;
}));

MIT-licensed