diff --git a/lib/proxy.js b/lib/proxy.js index 614aa59..e1e7f05 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -33,8 +33,12 @@ 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(); + var force = req.query.force || false; // Allow for a global cache to be specified on the parent Express app if (!options.cache) { @@ -56,7 +60,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); @@ -177,7 +181,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);