Skip to content

Commit 61c2889

Browse files
131jcrugzz
authored andcommitted
Do not rely on func.name (no scope)
1 parent fbc2668 commit 61c2889

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

lib/http-proxy.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
var http = require('http'),
2-
https = require('https'),
3-
url = require('url'),
4-
httpProxy = require('./http-proxy/index.js'); //use explicit /index.js to help browserify negociation in require '/lib/http-proxy' (!)
1+
//use explicit /index.js to help browserify negociation in require '/lib/http-proxy' (!)
2+
var ProxyServer = require('./http-proxy/index.js').Server;
53

6-
/**
7-
* Export the proxy "Server" as the main export.
8-
*/
9-
module.exports = httpProxy.Server;
104

115
/**
126
* Creates the proxy server.
@@ -23,9 +17,8 @@ module.exports = httpProxy.Server;
2317
* @api public
2418
*/
2519

26-
module.exports.createProxyServer =
27-
module.exports.createServer =
28-
module.exports.createProxy = function createProxyServer(options) {
20+
21+
var createProxyServer = function(options) {
2922
/*
3023
* `options` is needed and it must have the following layout:
3124
*
@@ -54,6 +47,19 @@ module.exports.createProxyServer =
5447
* }
5548
*/
5649

57-
return new httpProxy.Server(options);
58-
};
50+
return new ProxyServer(options);
51+
}
52+
53+
54+
ProxyServer.createProxyServer = createProxyServer;
55+
ProxyServer.createServer = createProxyServer;
56+
ProxyServer.createProxy = createProxyServer;
57+
58+
59+
60+
61+
/**
62+
* Export the proxy "Server" as the main export.
63+
*/
64+
module.exports = ProxyServer;
5965

lib/http-proxy/passes/web-outgoing.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var url = require('url'),
2-
common = require('../common'),
3-
passes = exports;
2+
common = require('../common');
3+
44

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

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

15-
[ // <--
15+
module.exports = { // <--
1616

1717
/**
1818
* If is a HTTP 1.0 request, remove chunk headers
@@ -23,7 +23,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
2323
*
2424
* @api private
2525
*/
26-
function removeChunked(req, res, proxyRes) {
26+
removeChunked : function (req, res, proxyRes) {
2727
if (req.httpVersion === '1.0') {
2828
delete proxyRes.headers['transfer-encoding'];
2929
}
@@ -39,15 +39,15 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
3939
*
4040
* @api private
4141
*/
42-
function setConnection(req, res, proxyRes) {
42+
setConnection: function(req, res, proxyRes) {
4343
if (req.httpVersion === '1.0') {
4444
proxyRes.headers.connection = req.headers.connection || 'close';
4545
} else if (req.httpVersion !== '2.0' && !proxyRes.headers.connection) {
4646
proxyRes.headers.connection = req.headers.connection || 'keep-alive';
4747
}
4848
},
4949

50-
function setRedirectHostRewrite(req, res, proxyRes, options) {
50+
setRedirectHostRewrite: function(req, res, proxyRes, options) {
5151
if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite)
5252
&& proxyRes.headers['location']
5353
&& redirectRegex.test(proxyRes.statusCode)) {
@@ -82,7 +82,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
8282
*
8383
* @api private
8484
*/
85-
function writeHeaders(req, res, proxyRes, options) {
85+
writeHeaders : function(req, res, proxyRes, options) {
8686
var rewriteCookieDomainConfig = options.cookieDomainRewrite;
8787
if (typeof rewriteCookieDomainConfig === 'string') { //also test for ''
8888
rewriteCookieDomainConfig = { '*': rewriteCookieDomainConfig };
@@ -107,7 +107,7 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
107107
*
108108
* @api private
109109
*/
110-
function writeStatusCode(req, res, proxyRes) {
110+
writeStatusCode : function(req, res, proxyRes) {
111111
// From Node.js docs: response.writeHead(statusCode[, statusMessage][, headers])
112112
if(proxyRes.statusMessage) {
113113
res.writeHead(proxyRes.statusCode, proxyRes.statusMessage);
@@ -116,7 +116,4 @@ var redirectRegex = /^201|30(1|2|7|8)$/;
116116
}
117117
}
118118

119-
] // <--
120-
.forEach(function(func) {
121-
passes[func.name] = func;
122-
});
119+
};

0 commit comments

Comments
 (0)