Skip to content

Commit

Permalink
Fix from http-party#1542
Browse files Browse the repository at this point in the history
  • Loading branch information
edspencer committed Nov 19, 2021
1 parent 9b96cd7 commit 30eb9af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
52 changes: 26 additions & 26 deletions lib/http-proxy/passes/web-incoming.js
@@ -1,10 +1,10 @@
var httpNative = require('http'),
httpsNative = require('https'),
web_o = require('./web-outgoing'),
common = require('../common'),
followRedirects = require('follow-redirects');
var httpNative = require('http'),
httpsNative = require('https'),
web_o = require('./web-outgoing'),
common = require('../common'),
followRedirects = require('follow-redirects');

web_o = Object.keys(web_o).map(function(pass) {
web_o = Object.keys(web_o).map(function (pass) {
return web_o[pass];
});

Expand Down Expand Up @@ -32,8 +32,8 @@ module.exports = {
*/

deleteLength: function deleteLength(req, res, options) {
if((req.method === 'DELETE' || req.method === 'OPTIONS')
&& !req.headers['content-length']) {
if ((req.method === 'DELETE' || req.method === 'OPTIONS')
&& !req.headers['content-length']) {
req.headers['content-length'] = '0';
delete req.headers['transfer-encoding'];
}
Expand All @@ -50,7 +50,7 @@ module.exports = {
*/

timeout: function timeout(req, res, options) {
if(options.timeout) {
if (options.timeout) {
req.socket.setTimeout(options.timeout);
}
},
Expand All @@ -66,16 +66,16 @@ module.exports = {
*/

XHeaders: function XHeaders(req, res, options) {
if(!options.xfwd) return;
if (!options.xfwd) return;

var encrypted = req.isSpdy || common.hasEncryptedConnection(req);
var values = {
for : req.connection.remoteAddress || req.socket.remoteAddress,
port : common.getPort(req),
for: req.connection.remoteAddress || req.socket.remoteAddress,
port: common.getPort(req),
proto: encrypted ? 'https' : 'http'
};

['for', 'port', 'proto'].forEach(function(header) {
['for', 'port', 'proto'].forEach(function (header) {
req.headers['x-forwarded-' + header] =
(req.headers['x-forwarded-' + header] || '') +
(req.headers['x-forwarded-' + header] ? ',' : '') +
Expand Down Expand Up @@ -106,7 +106,7 @@ module.exports = {
var http = agents.http;
var https = agents.https;

if(options.forward) {
if (options.forward) {
// If forward enable, so just pipe the request
var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
common.setupOutgoing(options.ssl || {}, options, req, 'forward')
Expand All @@ -119,7 +119,7 @@ module.exports = {
forwardReq.on('error', forwardError);

(options.buffer || req).pipe(forwardReq);
if(!options.target) { return res.end(); }
if (!options.target) { return res.end(); }
}

// Request initalization
Expand All @@ -128,17 +128,17 @@ module.exports = {
);

// Enable developers to modify the proxyReq before headers are sent
proxyReq.on('socket', function(socket) {
if(server && !proxyReq.getHeader('expect')) {
proxyReq.on('socket', function (socket) {
if (server && !proxyReq.getHeader('expect')) {
server.emit('proxyReq', proxyReq, req, res, options);
}
});

// allow outgoing socket to timeout so that we could
// show an error page at the initial request
if(options.proxyTimeout) {
proxyReq.setTimeout(options.proxyTimeout, function() {
proxyReq.abort();
if (options.proxyTimeout) {
proxyReq.setTimeout(options.proxyTimeout, function () {
proxyReq.abort();
});
}

Expand All @@ -154,7 +154,7 @@ module.exports = {

function createErrorHandler(proxyReq, url) {
return function proxyError(err) {
if (req.socket.destroyed && err.code === 'ECONNRESET') {
if (req.aborted && err.code === 'ECONNRESET') {
server.emit('econnreset', err, req, res, url);
return proxyReq.abort();
}
Expand All @@ -169,12 +169,12 @@ module.exports = {

(options.buffer || req).pipe(proxyReq);

proxyReq.on('response', function(proxyRes) {
if(server) { server.emit('proxyRes', proxyRes, req, res); }
proxyReq.on('response', function (proxyRes) {
if (server) { server.emit('proxyRes', proxyRes, req, res); }

if(!res.headersSent && !options.selfHandleResponse) {
for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes, options)) { break; }
if (!res.headersSent && !options.selfHandleResponse) {
for (var i = 0; i < web_o.length; i++) {
if (web_o[i](req, res, proxyRes, options)) { break; }
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "http-proxy",
"version": "1.18.1",
"name": "@oplabs/http-proxy",
"version": "1.18.2",
"repository": {
"type": "git",
"url": "https://github.com/http-party/node-http-proxy.git"
Expand Down Expand Up @@ -38,4 +38,4 @@
"node": ">=8.0.0"
},
"license": "MIT"
}
}

0 comments on commit 30eb9af

Please sign in to comment.