From 716df0c4fc6aa90c4ee33b320d7cbdbf48e392e7 Mon Sep 17 00:00:00 2001 From: Maor Hayun Date: Wed, 16 Nov 2016 16:59:28 +0200 Subject: [PATCH 1/2] added ability to forward client's headers --- lib/proxy.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/proxy.js b/lib/proxy.js index 2b1bda8..980b0f6 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -29,6 +29,9 @@ module.exports = function(options) { originalQuery: false }); + options.headersToPreserveInCache = + _.map(_.union(options.headersToPreserveInCache, headersToPreserveInCache), (h) => h.toLowerCase()); + return function(req, res, next) { var method = req.method.toUpperCase(); @@ -165,7 +168,7 @@ module.exports = function(options) { } // Store the headers as a separate cache entry - var headersToKeep = _.pick(resp.headers, headersToPreserveInCache); + var headersToKeep = _.pick(resp.headers, options.headersToPreserveInCache); if (_.isArray(options.transforms)) { apiRequest = applyTransforms(apiRequest, options.transforms, headersToKeep); From 01102aad96c7bd08eb561b4582a197d153d83943 Mon Sep 17 00:00:00 2001 From: Maor Hayun Date: Wed, 16 Nov 2016 17:13:35 +0200 Subject: [PATCH 2/2] force making request from api --- lib/proxy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/proxy.js b/lib/proxy.js index 980b0f6..757053c 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -34,6 +34,7 @@ module.exports = function(options) { return function(req, res, next) { var method = req.method.toUpperCase(); + var force = req.query.force || false; // Allow for a global cache to be specified on the parent Express app if (!options.cache) { @@ -55,7 +56,7 @@ module.exports = function(options) { } } - if (method.toUpperCase() === 'GET' && options.cache && options.cacheMaxAge > 0) { + if (method.toUpperCase() === 'GET' && options.cache && options.cacheMaxAge > 0 && !force) { if (!options.cache) return next(new Error('No cache provider configured')); return proxyViaCache(req, res, next);