From 61c28891093b256bbc0dae78e45e2c5f0acf2101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Leurent?= <131.php@cloudyks.org> Date: Tue, 20 Sep 2016 15:26:34 +0200 Subject: [PATCH] Do not rely on func.name (no scope) --- lib/http-proxy.js | 32 ++++++++++++++++----------- lib/http-proxy/passes/web-outgoing.js | 21 ++++++++---------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/http-proxy.js b/lib/http-proxy.js index 1614b27..44e723f 100644 --- a/lib/http-proxy.js +++ b/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. @@ -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; diff --git a/lib/http-proxy/passes/web-outgoing.js b/lib/http-proxy/passes/web-outgoing.js index 8bda893..69d383e 100644 --- a/lib/http-proxy/passes/web-outgoing.js +++ b/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)$/; @@ -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; - }); +};