Do not rely on func.name (no scope)

This commit is contained in:
François Leurent 2016-09-20 15:26:34 +02:00 committed by Jarrett Cruger
parent fbc266809c
commit 61c2889109
2 changed files with 28 additions and 25 deletions

View File

@ -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.
@ -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:
*
@ -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;

View File

@ -1,6 +1,6 @@
var url = require('url'),
common = require('../common'),
passes = exports;
common = require('../common');
var redirectRegex = /^201|30(1|2|7|8)$/;
@ -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
@ -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'];
}
@ -39,7 +39,7 @@ 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) {
@ -47,7 +47,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
}
},
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)) {
@ -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 };
@ -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);
@ -116,7 +116,4 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
}
}
] // <--
.forEach(function(func) {
passes[func.name] = func;
});
};