Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down