Skip to content

Commit

Permalink
Do not rely on func.name (no scope)
Browse files Browse the repository at this point in the history
  • Loading branch information
131 authored and jcrugzz committed Oct 22, 2016
1 parent fbc2668 commit 61c2889
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
32 changes: 19 additions & 13 deletions lib/http-proxy.js
@@ -1,12 +1,6 @@
var http = require('http'),
https = require('https'),
url = require('url'),
httpProxy = require('./http-proxy/index.js'); //use explicit /index.js to help browserify negociation in require '/lib/http-proxy' (!)
//use explicit /index.js to help browserify negociation in require '/lib/http-proxy' (!)
var ProxyServer = require('./http-proxy/index.js').Server;

/**
* Export the proxy "Server" as the main export.
*/
module.exports = httpProxy.Server;

/**
* Creates the proxy server.
Expand All @@ -23,9 +17,8 @@ module.exports = httpProxy.Server;
* @api public
*/

module.exports.createProxyServer =
module.exports.createServer =
module.exports.createProxy = function createProxyServer(options) {

var createProxyServer = function(options) {
/*
* `options` is needed and it must have the following layout:
*
Expand Down Expand Up @@ -54,6 +47,19 @@ module.exports.createProxyServer =
* }
*/

return new httpProxy.Server(options);
};
return new ProxyServer(options);
}


ProxyServer.createProxyServer = createProxyServer;
ProxyServer.createServer = createProxyServer;
ProxyServer.createProxy = createProxyServer;




/**
* Export the proxy "Server" as the main export.
*/
module.exports = ProxyServer;

21 changes: 9 additions & 12 deletions lib/http-proxy/passes/web-outgoing.js
@@ -1,6 +1,6 @@
var url = require('url'),
common = require('../common'),
passes = exports;
common = require('../common');


var redirectRegex = /^201|30(1|2|7|8)$/;

Expand All @@ -12,7 +12,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
* flexible.
*/

[ // <--
module.exports = { // <--

/**
* If is a HTTP 1.0 request, remove chunk headers
Expand All @@ -23,7 +23,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
*
* @api private
*/
function removeChunked(req, res, proxyRes) {
removeChunked : function (req, res, proxyRes) {
if (req.httpVersion === '1.0') {
delete proxyRes.headers['transfer-encoding'];
}
Expand All @@ -39,15 +39,15 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
*
* @api private
*/
function setConnection(req, res, proxyRes) {
setConnection: function(req, res, proxyRes) {
if (req.httpVersion === '1.0') {
proxyRes.headers.connection = req.headers.connection || 'close';
} else if (req.httpVersion !== '2.0' && !proxyRes.headers.connection) {
proxyRes.headers.connection = req.headers.connection || 'keep-alive';
}
},

function setRedirectHostRewrite(req, res, proxyRes, options) {
setRedirectHostRewrite: function(req, res, proxyRes, options) {
if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite)
&& proxyRes.headers['location']
&& redirectRegex.test(proxyRes.statusCode)) {
Expand Down Expand Up @@ -82,7 +82,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
*
* @api private
*/
function writeHeaders(req, res, proxyRes, options) {
writeHeaders : function(req, res, proxyRes, options) {
var rewriteCookieDomainConfig = options.cookieDomainRewrite;
if (typeof rewriteCookieDomainConfig === 'string') { //also test for ''
rewriteCookieDomainConfig = { '*': rewriteCookieDomainConfig };
Expand All @@ -107,7 +107,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
*
* @api private
*/
function writeStatusCode(req, res, proxyRes) {
writeStatusCode : function(req, res, proxyRes) {
// From Node.js docs: response.writeHead(statusCode[, statusMessage][, headers])
if(proxyRes.statusMessage) {
res.writeHead(proxyRes.statusCode, proxyRes.statusMessage);
Expand All @@ -116,7 +116,4 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
}
}

] // <--
.forEach(function(func) {
passes[func.name] = func;
});
};

0 comments on commit 61c2889

Please sign in to comment.