Skip to content

stephank/upgradeEx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Response object for HTTP Upgrade/CONNECT

Resources

Stars

Watchers

Forks

Packages

No packages published