From d48f67eb90d8af66211093e91efdd6638859e0bf 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:32:14 +0200 Subject: [PATCH] Do not rely on func.name (no scope) --- lib/http-proxy/passes/web-incoming.js | 19 ++++++++----------- lib/http-proxy/passes/ws-incoming.js | 18 ++++++------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/http-proxy/passes/web-incoming.js b/lib/http-proxy/passes/web-incoming.js index 5858d63..6ff6e07 100644 --- a/lib/http-proxy/passes/web-incoming.js +++ b/lib/http-proxy/passes/web-incoming.js @@ -1,8 +1,7 @@ var http = require('http'), https = require('https'), web_o = require('./web-outgoing'), - common = require('../common'), - passes = exports; + common = require('../common'); web_o = Object.keys(web_o).map(function(pass) { return web_o[pass]; @@ -16,7 +15,8 @@ web_o = Object.keys(web_o).map(function(pass) { * flexible. */ -[ // <-- + +module.exports = { /** * Sets `content-length` to '0' if request is of DELETE type. @@ -28,7 +28,7 @@ web_o = Object.keys(web_o).map(function(pass) { * @api private */ - function deleteLength(req, res, options) { + deleteLength : function(req, res, options) { if((req.method === 'DELETE' || req.method === 'OPTIONS') && !req.headers['content-length']) { req.headers['content-length'] = '0'; @@ -46,7 +46,7 @@ web_o = Object.keys(web_o).map(function(pass) { * @api private */ - function timeout(req, res, options) { + timeout: function(req, res, options) { if(options.timeout) { req.socket.setTimeout(options.timeout); } @@ -62,7 +62,7 @@ web_o = Object.keys(web_o).map(function(pass) { * @api private */ - function XHeaders(req, res, options) { + XHeaders : function(req, res, options) { if(!options.xfwd) return; var encrypted = req.isSpdy || common.hasEncryptedConnection(req); @@ -94,7 +94,7 @@ web_o = Object.keys(web_o).map(function(pass) { * @api private */ - function stream(req, res, options, _, server, clb) { + stream : function(req, res, options, _, server, clb) { // And we begin! server.emit('start', req, res, options.target) @@ -168,7 +168,4 @@ web_o = Object.keys(web_o).map(function(pass) { //proxyReq.end(); } -] // <-- - .forEach(function(func) { - passes[func.name] = func; - }); +}; diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index a6ddb31..1dfe1fa 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -1,7 +1,6 @@ var http = require('http'), https = require('https'), - common = require('../common'), - passes = exports; + common = require('../common'); /*! * Array of passes. @@ -16,9 +15,8 @@ var http = require('http'), * */ -var passes = exports; -[ +module.exports = { /** * WebSocket requests must have the `GET` method and * the `upgrade:websocket` header @@ -29,7 +27,7 @@ var passes = exports; * @api private */ - function checkMethodAndHeader (req, socket) { + checkMethodAndHeader : function (req, socket) { if (req.method !== 'GET' || !req.headers.upgrade) { socket.destroy(); return true; @@ -51,7 +49,7 @@ var passes = exports; * @api private */ - function XHeaders(req, socket, options) { + XHeaders : function(req, socket, options) { if(!options.xfwd) return; var values = { @@ -78,7 +76,7 @@ var passes = exports; * * @api private */ - function stream(req, socket, options, head, server, clb) { + stream : function(req, socket, options, head, server, clb) { common.setupSocket(socket); if (head && head.length) socket.unshift(head); @@ -155,8 +153,4 @@ var passes = exports; socket.end(); } } - -] // <-- - .forEach(function(func) { - passes[func.name] = func; - }); +};