express-http-proxy
Advanced tools
Comparing version 1.6.3 to 2.0.0
@@ -17,3 +17,3 @@ 'use strict'; | ||
.all([parseBody, createReqOptions]) | ||
.then(function(responseArray) { | ||
.then(function (responseArray) { | ||
Container.proxy.bodyContent = responseArray[0]; | ||
@@ -20,0 +20,0 @@ Container.proxy.reqBuilder = responseArray[1]; |
'use strict'; | ||
function copyProxyResHeadersToUserRes(container) { | ||
return new Promise(function(resolve) { | ||
return new Promise(function (resolve) { | ||
var res = container.user.res; | ||
@@ -9,7 +9,7 @@ var rsp = container.proxy.res; | ||
if (!res.headersSent) { | ||
res.status(rsp.statusCode); | ||
Object.keys(rsp.headers) | ||
.filter(function(item) { return item !== 'transfer-encoding'; }) | ||
.forEach(function(item) { | ||
res.set(item, rsp.headers[item]); | ||
res.status(rsp.statusCode); | ||
Object.keys(rsp.headers) | ||
.filter(function (item) { return item !== 'transfer-encoding'; }) | ||
.forEach(function (item) { | ||
res.set(item, rsp.headers[item]); | ||
}); | ||
@@ -16,0 +16,0 @@ } |
@@ -19,3 +19,3 @@ 'use strict'; | ||
.resolve(resolverFn(container.proxy.bodyContent, container.user.req)) | ||
.then(function(bodyContent) { | ||
.then(function (bodyContent) { | ||
container.proxy.bodyContent = bodyContent; | ||
@@ -22,0 +22,0 @@ return Promise.resolve(container); |
@@ -12,7 +12,7 @@ 'use strict'; | ||
function zipOrUnzip(method) { | ||
return function(rspData, res) { | ||
return function (rspData, res) { | ||
return new Promise(function (resolve, reject) { | ||
if (isResGzipped(res) && rspData.length) { | ||
zlib[method](rspData, function(err, buffer) { | ||
if(err) { | ||
zlib[method](rspData, function (err, buffer) { | ||
if (err) { | ||
reject(err); | ||
@@ -41,7 +41,7 @@ } else { | ||
if (!res.headersSent) { | ||
res.set('content-length', rspdAfter.length); | ||
res.set('content-length', rspdAfter.length); | ||
} else if (rspdAfter.length !== rspdBefore.length) { | ||
var error = '"Content-Length" is already sent,' + | ||
var error = '"Content-Length" is already sent,' + | ||
'the length of response data can not be changed'; | ||
return reject(new Error(error)); | ||
return reject(new Error(error)); | ||
} | ||
@@ -61,3 +61,3 @@ } | ||
var res = container.user.res; | ||
var originalResData; | ||
var originalResData; | ||
@@ -70,15 +70,15 @@ if (res.statusCode === 304) { | ||
return proxyResDataPromise | ||
.then(function(proxyResData){ | ||
.then(function (proxyResData) { | ||
originalResData = proxyResData; | ||
return resolverFn(proxyRes, proxyResData, req, res); | ||
}) | ||
.then(function(modifiedResData) { | ||
return new Promise(function(resolve, reject) { | ||
.then(function (modifiedResData) { | ||
return new Promise(function (resolve, reject) { | ||
var rspd = as.buffer(modifiedResData, container.options); | ||
verifyBuffer(rspd, reject); | ||
updateHeaders(res, originalResData, rspd, reject); | ||
maybeZipPromise(rspd, container.proxy.res).then(function(buffer) { | ||
maybeZipPromise(rspd, container.proxy.res).then(function (buffer) { | ||
container.proxy.resData = buffer; | ||
resolve(container); | ||
}).catch(function(error){ | ||
}).catch(function (error) { | ||
reject(error); | ||
@@ -85,0 +85,0 @@ }); |
'use strict'; | ||
var getHeaders = require('../../lib/getHeaders'); | ||
function decorateUserResHeaders(container) { | ||
var resolverFn = container.options.userResHeaderDecorator; | ||
var headers = container.user.res.getHeaders ? container.user.res.getHeaders() : container.user.res._headers; | ||
var headers = getHeaders(container.user.res); | ||
@@ -13,11 +13,11 @@ if (!resolverFn) { | ||
const clearAllHeaders = (res) => { | ||
for (const header in res._headers) { | ||
res.removeHeader(header) | ||
for (const header in getHeaders(res)) { | ||
res.removeHeader(header); | ||
} | ||
} | ||
}; | ||
return Promise | ||
.resolve(resolverFn(headers, container.user.req, container.user.res, container.proxy.req, container.proxy.res)) | ||
.then(function(headers) { | ||
return new Promise(function(resolve) { | ||
.then(function (headers) { | ||
return new Promise(function (resolve) { | ||
clearAllHeaders(container.user.res); | ||
@@ -24,0 +24,0 @@ container.user.res.set(headers); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
res.setHeader('X-Timeout-Reason', 'express-http-proxy reset the request.'); | ||
res.writeHead(504, {'Content-Type': 'text/plain'}); | ||
res.writeHead(504, { 'Content-Type': 'text/plain' }); | ||
res.end(); | ||
@@ -12,0 +12,0 @@ } |
@@ -19,5 +19,5 @@ 'use strict'; | ||
} | ||
}) | ||
}); | ||
} | ||
module.exports = maybeSkipToNextHandler; |
@@ -18,3 +18,3 @@ 'use strict'; | ||
function prepareProxyReq(container) { | ||
return new Promise(function(resolve) { | ||
return new Promise(function (resolve) { | ||
var bodyContent = container.proxy.bodyContent; | ||
@@ -21,0 +21,0 @@ var reqOpt = container.proxy.reqBuilder; |
@@ -15,3 +15,3 @@ 'use strict'; | ||
.resolve(resolverFn(container.user.req)) | ||
.then(function(resolvedPath) { | ||
.then(function (resolvedPath) { | ||
container.proxy.reqBuilder.path = resolvedPath; | ||
@@ -18,0 +18,0 @@ debug('resolved proxy path:', resolvedPath); |
@@ -11,5 +11,5 @@ 'use strict'; | ||
return new Promise(function(resolve, reject) { | ||
return new Promise(function (resolve, reject) { | ||
var protocol = Container.proxy.requestModule; | ||
var proxyReq = Container.proxy.req = protocol.request(reqOpt, function(rsp) { | ||
var proxyReq = Container.proxy.req = protocol.request(reqOpt, function (rsp) { | ||
if (options.stream) { | ||
@@ -21,4 +21,4 @@ Container.proxy.res = rsp; | ||
var chunks = []; | ||
rsp.on('data', function(chunk) { chunks.push(chunk); }); | ||
rsp.on('end', function() { | ||
rsp.on('data', function (chunk) { chunks.push(chunk); }); | ||
rsp.on('end', function () { | ||
Container.proxy.res = rsp; | ||
@@ -31,5 +31,5 @@ Container.proxy.resData = Buffer.concat(chunks, chunkLength(chunks)); | ||
proxyReq.on('socket', function(socket) { | ||
proxyReq.on('socket', function (socket) { | ||
if (options.timeout) { | ||
socket.setTimeout(options.timeout, function() { | ||
socket.setTimeout(options.timeout, function () { | ||
proxyReq.abort(); | ||
@@ -43,2 +43,3 @@ }); | ||
// this guy should go elsewhere, down the chain | ||
if (options.parseReqBody) { | ||
@@ -49,5 +50,5 @@ // We are parsing the body ourselves so we need to write the body content | ||
//if (bodyContent instanceof Object) { | ||
//throw new Error | ||
//debugger; | ||
//bodyContent = JSON.stringify(bodyContent); | ||
//throw new Error | ||
//debugger; | ||
//bodyContent = JSON.stringify(bodyContent); | ||
//} | ||
@@ -61,3 +62,3 @@ | ||
var params = JSON.parse(body); | ||
body = Object.keys(params).map(function(k) { return k + '=' + params[k]; }).join('&'); | ||
body = Object.keys(params).map(function (k) { return k + '=' + params[k]; }).join('&'); | ||
} catch (e) { | ||
@@ -73,7 +74,9 @@ // bodyContent is not json-format | ||
// Pipe will call end when it has completely read from the request. | ||
req.pipe(proxyReq); | ||
} | ||
req.on('aborted', function() { | ||
req.on('aborted', function () { | ||
// reject? | ||
proxyReq.abort(); | ||
@@ -80,0 +83,0 @@ }); |
{ | ||
"name": "express-http-proxy", | ||
"version": "1.6.3", | ||
"version": "2.0.0", | ||
"description": "http proxy middleware for express", | ||
@@ -13,3 +13,3 @@ "engines": { | ||
"mocha": "mocha -R spec test --recursive --exit", | ||
"lint": "eslint index.js **/*js" | ||
"lint": "eslint index.js app/**/*js lib/*js" | ||
}, | ||
@@ -35,7 +35,7 @@ "repository": { | ||
"cookie-parser": "^1.4.3", | ||
"eslint": "^4.19.1", | ||
"eslint": "^8.48.0", | ||
"express": "^4.15.4", | ||
"mocha": "^8.0.1", | ||
"nock": "^10.0.6", | ||
"supertest": "^3.4.2" | ||
"mocha": "^10.2.0", | ||
"nock": "^13.3.3", | ||
"supertest": "^6.3.3" | ||
}, | ||
@@ -42,0 +42,0 @@ "dependencies": { |
@@ -578,2 +578,4 @@ # express-http-proxy [![NPM version](https://badge.fury.io/js/express-http-proxy.svg)](http://badge.fury.io/js/express-http-proxy) [![Build Status](https://travis-ci.org/villadora/express-http-proxy.svg?branch=master)](https://travis-ci.org/villadora/express-http-proxy) | ||
| --- | --- | | ||
| 2.0.0 | Update all dependencies; set stage for next iteration. `express-http-proxy` interface has not changed, but the underlying libraries are not guaranteed to be backward compatible. Versions beyond this point are expected to be run in node verions >= 16. | | ||
| ----- | ----------------------------------------------------------------------- | | ||
| 1.6.3 | [#453] Author should be able to delete headers in userResHeaderDecorator. | ||
@@ -580,0 +582,0 @@ | 1.6.2 | Update node.js versions used by ci. | |
@@ -15,3 +15,3 @@ 'use strict'; | ||
http = express(); | ||
http.use(proxy('http://httpbin.org', { | ||
http.use(proxy('https://httpbin.org', { | ||
headers: { | ||
@@ -18,0 +18,0 @@ 'X-Current-president': 'taft' |
@@ -44,3 +44,3 @@ 'use strict'; | ||
var app = express(); | ||
app.use(proxy('httpbin.org', { | ||
app.use(proxy('https://httpbin.org', { | ||
userResDecorator: function (proxyRes, proxyResData) { | ||
@@ -60,3 +60,3 @@ assert(proxyRes.connection); | ||
var app = express(); | ||
app.use(proxy('httpbin.org', { | ||
app.use(proxy('https://httpbin.org', { | ||
userResDecorator: function (proxyRes, proxyResData) { | ||
@@ -85,3 +85,3 @@ return new Promise(function (resolve) { | ||
var app = express(); | ||
app.use(proxy('httpbin.org', { | ||
app.use(proxy('https://httpbin.org', { | ||
userResDecorator: function (proxyRes, proxyResData) { | ||
@@ -107,3 +107,3 @@ proxyResData = JSON.parse(proxyResData.toString('utf8')); | ||
var app = express(); | ||
app.use(proxy('httpbin.org', { | ||
app.use(proxy('https://httpbin.org', { | ||
userResDecorator: function (rsp, data, req, res) { | ||
@@ -110,0 +110,0 @@ res.set('x-wombat-alliance', 'mammels'); |
@@ -26,3 +26,3 @@ 'use strict'; | ||
if (err) { return done(err); } | ||
assert(/node-superagent/.test(res.body.headers['User-Agent'])); | ||
assert(/httpbin.org/.test(res.body.headers['Host'])); | ||
assert.equal(res.body.url, 'http://httpbin.org/get'); | ||
@@ -29,0 +29,0 @@ done(err); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116040
59
2759
613