Showing with 21 additions and 15 deletions.
  1. +3 −8 lib/http-proxy.js
  2. +2 −7 lib/http-proxy/index.js
  3. +16 −0 lib/http-proxy/passes/web-incoming.js
@@ -8,13 +8,6 @@ var http = require('http'),
*/
module.exports = httpProxy.Server;

module.exports.createProxy = function(options) {
return {
web: httpProxy.createRightProxy('web')(options),
ws: httpProxy.createRightProxy('ws')(options)
};
}

/**
* Creates the proxy server.
*
@@ -30,7 +23,9 @@ module.exports.createProxy = function(options) {
* @api public
*/

module.exports.createProxyServer = module.exports.createServer = function createProxyServer(options) {
module.exports.createProxyServer =
module.exports.createServer =
module.exports.createProxy = function createProxyServer(options) {
/*
* `options` is needed and it must have the following layout:
*
@@ -26,15 +26,10 @@ httpProxy.Server = ProxyServer;
*/

function createRightProxy(type) {
var webPasses = Object.keys(web).map(function(pass) {
return web[pass];
});
var wsPasses = Object.keys(ws).map(function(pass) {
return ws[pass];
});

return function(options) {
return function(req, res /*, [head], [opts] */) {
var passes = (type === 'ws') ? (this.wsPasses || wsPasses) : (this.webPasses || webPasses),
var passes = (type === 'ws') ? this.wsPasses : this.webPasses,
args = [].slice.call(arguments),
cntr = args.length - 1,
head, cbl;
@@ -90,6 +90,13 @@ web_o = Object.keys(web_o).map(function(pass) {
*/

function stream(req, res, options, _, server, clb) {

//
// And we begin!
//
if (!clb) {
server.emit('start', req, res, options.target)
}
if(options.forward) {
// If forward enable, so just pipe the request
var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
@@ -122,6 +129,15 @@ web_o = Object.keys(web_o).map(function(pass) {
if(web_o[i](req, res, proxyRes)) { break; }
}

//
// Allow us to listen when the proxy has completed
//
proxyRes.on('end', function () {
if (!clb) {
server.emit('end', req, res, proxyRes);
}
})

proxyRes.pipe(res);
});