Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • N node-http-proxy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 482
    • Issues 482
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 102
    • Merge requests 102
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • http ... PARTY!
  • node-http-proxy
  • Merge requests
  • !1243

Fix for proxy server storing the requests as global variables

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/ryank311/master into master 7 years ago
  • Overview 0
  • Commits 6
  • Pipelines 0
  • Changes 5

Created by: ryank311

Under high concurrency, we are seeing requests getting mixed up from the proxy server and our other express routes. This is believed to be caused by the fact that this app is using var to declare all variables, which makes them on the global scope. When we use async and await to process the headers for proxy requests, it causes requests to get mixed up across users.

Compare
  • master (base)

and
  • latest version
    59f29427
    6 commits, 2 years ago

5 files
+ 30
- 30

    Preferences

    File browser
    Compare changes
lib/htt‎p-proxy‎
pas‎ses‎
web-inc‎oming.js‎ +7 -7
web-out‎going.js‎ +6 -6
ws-inco‎ming.js‎ +4 -4
comm‎on.js‎ +6 -6
inde‎x.js‎ +7 -7
lib/http-proxy/passes/web-incoming.js
+ 7
- 7
  • View file @ 59f29427


@@ -65,8 +65,8 @@ module.exports = {
XHeaders: function XHeaders(req, res, options) {
if(!options.xfwd) return;
var encrypted = req.isSpdy || common.hasEncryptedConnection(req);
var values = {
let encrypted = req.isSpdy || common.hasEncryptedConnection(req);
let values = {
for : req.connection.remoteAddress || req.socket.remoteAddress,
port : common.getPort(req),
proto: encrypted ? 'https' : 'http'
@@ -101,13 +101,13 @@ module.exports = {
if(options.forward) {
// If forward enable, so just pipe the request
var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
let forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
common.setupOutgoing(options.ssl || {}, options, req, 'forward')
);
// error handler (e.g. ECONNRESET, ECONNREFUSED)
// Handle errors on incoming request as well as it makes sense to
var forwardError = createErrorHandler(forwardReq, options.forward);
let forwardError = createErrorHandler(forwardReq, options.forward);
req.on('error', forwardError);
forwardReq.on('error', forwardError);
@@ -116,7 +116,7 @@ module.exports = {
}
// Request initalization
var proxyReq = (options.target.protocol === 'https:' ? https : http).request(
let proxyReq = (options.target.protocol === 'https:' ? https : http).request(
common.setupOutgoing(options.ssl || {}, options, req)
);
@@ -139,7 +139,7 @@ module.exports = {
});
// handle errors in proxy and incoming request, just like for forward proxy
var proxyError = createErrorHandler(proxyReq, options.target);
let proxyError = createErrorHandler(proxyReq, options.target);
req.on('error', proxyError);
proxyReq.on('error', proxyError);
@@ -162,7 +162,7 @@ module.exports = {
proxyReq.on('response', function(proxyRes) {
if(server) { server.emit('proxyRes', proxyRes, req, res); }
for(var i=0; i < web_o.length; i++) {
for(let i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes, options)) { break; }
}
lib/http-proxy/passes/web-outgoing.js
+ 6
- 6
  • View file @ 59f29427


@@ -51,8 +51,8 @@ module.exports = { // <--
if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite)
&& proxyRes.headers['location']
&& redirectRegex.test(proxyRes.statusCode)) {
var target = url.parse(options.target);
var u = url.parse(proxyRes.headers['location']);
let target = url.parse(options.target);
let u = url.parse(proxyRes.headers['location']);
// make sure the redirected host matches the target host before rewriting
if (target.host != u.host) {
@@ -83,7 +83,7 @@ module.exports = { // <--
* @api private
*/
writeHeaders: function writeHeaders(req, res, proxyRes, options) {
var rewriteCookieDomainConfig = options.cookieDomainRewrite,
let rewriteCookieDomainConfig = options.cookieDomainRewrite,
preserveHeaderKeyCase = options.preserveHeaderKeyCase,
rawHeaderKeyMap,
setHeader = function(key, header) {
@@ -102,14 +102,14 @@ module.exports = { // <--
// https://nodejs.org/api/http.html#http_message_rawheaders
if (preserveHeaderKeyCase && proxyRes.rawHeaders != undefined) {
rawHeaderKeyMap = {};
for (var i = 0; i < proxyRes.rawHeaders.length; i += 2) {
var key = proxyRes.rawHeaders[i];
for (let i = 0; i < proxyRes.rawHeaders.length; i += 2) {
let key = proxyRes.rawHeaders[i];
rawHeaderKeyMap[key.toLowerCase()] = key;
}
}
Object.keys(proxyRes.headers).forEach(function(key) {
var header = proxyRes.headers[key];
let header = proxyRes.headers[key];
if (preserveHeaderKeyCase && rawHeaderKeyMap) {
key = rawHeaderKeyMap[key] || key;
}
lib/http-proxy/passes/ws-incoming.js
+ 4
- 4
  • View file @ 59f29427


@@ -52,7 +52,7 @@ module.exports = {
XHeaders : function XHeaders(req, socket, options) {
if(!options.xfwd) return;
var values = {
let values = {
for : req.connection.remoteAddress || req.socket.remoteAddress,
port : common.getPort(req),
proto: common.hasEncryptedConnection(req) ? 'wss' : 'ws'
@@ -82,7 +82,7 @@ module.exports = {
if (head && head.length) socket.unshift(head);
var proxyReq = (common.isSSL.test(options.target.protocol) ? https : http).request(
let proxyReq = (common.isSSL.test(options.target.protocol) ? https : http).request(
common.setupOutgoing(options.ssl || {}, options, req)
);
@@ -121,14 +121,14 @@ module.exports = {
//
socket.write(
Object.keys(proxyRes.headers).reduce(function (head, key) {
var value = proxyRes.headers[key];
let value = proxyRes.headers[key];
if (!Array.isArray(value)) {
head.push(key + ': ' + value);
return head;
}
for (var i = 0; i < value.length; i++) {
for (let i = 0; i < value.length; i++) {
head.push(key + ': ' + value[i]);
}
return head;
lib/http-proxy/common.js
+ 6
- 6
  • View file @ 59f29427


@@ -76,15 +76,15 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
// the final path is target path + relative path requested by user:
var target = options[forward || 'target'];
var targetPath = target && options.prependPath !== false
let target = options[forward || 'target'];
let targetPath = target && options.prependPath !== false
? (target.path || '')
: '';
//
// Remark: Can we somehow not use url.parse as a perf optimization?
//
var outgoingPath = !options.toProxy
let outgoingPath = !options.toProxy
? (url.parse(req.url).path || '')
: req.url;
@@ -142,7 +142,7 @@ common.setupSocket = function(socket) {
* @api private
*/
common.getPort = function(req) {
var res = req.headers.host ? req.headers.host.match(/:(\d+)/) : '';
let res = req.headers.host ? req.headers.host.match(/:(\d+)/) : '';
return res ?
res[1] :
@@ -174,7 +174,7 @@ common.urlJoin = function() {
//
// We do not want to mess with the query string. All we want to touch is the path.
//
var args = Array.prototype.slice.call(arguments),
let args = Array.prototype.slice.call(arguments),
lastIndex = args.length - 1,
last = args[lastIndex],
lastSegs = last.split('?'),
@@ -218,7 +218,7 @@ common.rewriteCookieDomain = function rewriteCookieDomain(header, config) {
});
}
return header.replace(cookieDomainRegex, function(match, prefix, previousDomain) {
var newDomain;
let newDomain;
if (previousDomain in config) {
newDomain = config[previousDomain];
} else if ('*' in config) {
lib/http-proxy/index.js
+ 7
- 7
  • View file @ 59f29427


@@ -29,7 +29,7 @@ function createRightProxy(type) {
return function(options) {
return function(req, res /*, [head], [opts] */) {
var passes = (type === 'ws') ? this.wsPasses : this.webPasses,
let passes = (type === 'ws') ? this.wsPasses : this.webPasses,
args = [].slice.call(arguments),
cntr = args.length - 1,
head, cbl;
@@ -41,7 +41,7 @@ function createRightProxy(type) {
cntr--;
}
var requestOptions = options;
let requestOptions = options;
if(
!(args[cntr] instanceof Buffer) &&
args[cntr] !== res
@@ -69,7 +69,7 @@ function createRightProxy(type) {
return this.emit('error', new Error('Must provide a proper URL as target'));
}
for(var i=0; i < passes.length; i++) {
for(let i=0; i < passes.length; i++) {
/**
* Call of passes functions
* pass(req, res, options, head)
@@ -122,7 +122,7 @@ ProxyServer.prototype.onError = function (err) {
};
ProxyServer.prototype.listen = function(port, hostname) {
var self = this,
let self = this,
closure = function(req, res) { self.web(req, res); };
this._server = this.options.ssl ?
@@ -139,7 +139,7 @@ ProxyServer.prototype.listen = function(port, hostname) {
};
ProxyServer.prototype.close = function(callback) {
var self = this;
let self = this;
if (this._server) {
this._server.close(done);
}
@@ -157,7 +157,7 @@ ProxyServer.prototype.before = function(type, passName, callback) {
if (type !== 'ws' && type !== 'web') {
throw new Error('type must be `web` or `ws`');
}
var passes = (type === 'ws') ? this.wsPasses : this.webPasses,
let passes = (type === 'ws') ? this.wsPasses : this.webPasses,
i = false;
passes.forEach(function(v, idx) {
@@ -172,7 +172,7 @@ ProxyServer.prototype.after = function(type, passName, callback) {
if (type !== 'ws' && type !== 'web') {
throw new Error('type must be `web` or `ws`');
}
var passes = (type === 'ws') ? this.wsPasses : this.webPasses,
let passes = (type === 'ws') ? this.wsPasses : this.webPasses,
i = false;
passes.forEach(function(v, idx) {
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: http-party/node-http-proxy!665
Source branch: github/fork/ryank311/master

Menu

Explore Projects Groups Snippets