upgrade-ex

0.2.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i upgrade-ex

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • stephank