Socket
Socket
Sign inDemoInstall

http-proxy

Package Overview
Dependencies
Maintainers
0
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-proxy - npm Package Compare versions

Comparing version 0.5.11 to 0.6.0

25

lib/node-http-proxy.js

@@ -331,2 +331,3 @@ /*

// options.https {Object|boolean} Settings for https.
// options.enableXForwarded {boolean} Don't clobber x-forwarded headers to allow layered proxies.
//

@@ -344,2 +345,4 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {

options.port = options.port || this.target.port;
options.enableXForwarded =
(undefined === options.enableXForwarded ? true : options.enableXForwarded);

@@ -384,5 +387,7 @@ //

//
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
req.headers['x-forwarded-proto'] = res.connection.pair ? 'https' : 'http';
if (options.enableXForwarded == true) {
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
req.headers['x-forwarded-proto'] = res.connection.pair ? 'https' : 'http';
}

@@ -589,2 +594,16 @@ //

options = options || {};
options.host = options.host || this.target.host;
options.port = options.port || this.target.port;
if (this.proxyTable && !options.host) {
location = this.proxyTable.getProxyLocation(req);
if (!location) {
res.writeHead(404);
return res.end();
}
options.port = location.port;
options.host = location.host;
}
//

@@ -591,0 +610,0 @@ // WebSocket requests must have the `GET` method and

2

package.json
{
"name": "http-proxy",
"description": "A full-featured http reverse proxy for node.js",
"version": "0.5.11",
"version": "0.6.0",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",

@@ -6,0 +6,0 @@ "contributors": [

@@ -124,2 +124,6 @@ /*

//
// WebSocketTest
//
TestRunner.prototype.webSocketTest = function (options) {

@@ -159,2 +163,38 @@ var self = this;

//
// WebSocketTestWithTable
//
TestRunner.prototype.webSocketTestWithTable = function (options) {
var self = this;
this.startTargetServer(options.ports.target, 'hello websocket', function (err, target) {
var socket = options.io.listen(target);
if (options.onListen) {
options.onListen(socket);
}
self.startProxyServerWithTable(
options.ports.proxy,
{router: options.router},
function (err, proxy) {
if (options.onServer) { options.onServer(proxy) }
//
// Setup the web socket against our proxy
//
var uri = options.wsprotocol + '://' + options.host + ':' + options.ports.proxy;
var ws = new websocket.WebSocket(uri + '/socket.io/websocket/', 'borf', {
origin: options.protocol + '://' + options.host
});
if (options.onWsupgrade) { ws.on('wsupgrade', options.onWsupgrade) }
if (options.onMessage) { ws.on('message', options.onMessage) }
if (options.onOpen) { ws.on('open', function () { options.onOpen(ws) }) }
}
);
});
}
//
// Creates the reverse proxy server

@@ -161,0 +201,0 @@ //

@@ -51,2 +51,46 @@ /*

vows.describe('node-http-proxy/websocket/' + wsprotocol).addBatch({
"when using proxy table":{
"with no latency" : {
"when an inbound message is sent from a WebSocket client": {
topic: function () {
var that = this
headers = {};
runner.webSocketTestWithTable({
io: io,
host: 'localhost',
wsprotocol: wsprotocol,
protocol: protocol,
router: {'localhost':'localhost:8230'},
ports: {
target: 8230,
proxy: 8231
},
onListen: function (socket) {
socket.on('connection', function (client) {
client.on('message', function (msg) {
that.callback(null, msg, headers);
});
});
},
onWsupgrade: function (req, res) {
headers.request = req;
headers.response = res.headers;
},
onOpen: function (ws) {
ws.send(utils.encode('from client'));
}
});
},
"the target server should receive the message": function (err, msg, headers) {
assert.equal(msg, 'from client');
},
"the origin and sec-websocket-origin headers should match": function (err, msg, headers) {
assert.isString(headers.response['sec-websocket-location']);
assert.isTrue(headers.response['sec-websocket-location'].indexOf(wsprotocol) !== -1);
assert.equal(headers.request.Origin, headers.response['sec-websocket-origin']);
}
}
}
},
"When using server created by httpProxy.createServer()": {

@@ -118,2 +162,3 @@ "with no latency" : {

"should raise the `websocket:incoming` event": function (ign, data) {
console.log(ign,data,utils.decode(data))
assert.equal(utils.decode(data.toString().replace('\u0000', '')), 'from client');

@@ -120,0 +165,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc