caching_middleware: ignore query string when generating cacheKey
parent
0dbec84794
commit
b9c82f78b1
|
@ -21,6 +21,7 @@ var path = require('path');
|
||||||
var zlib = require('zlib');
|
var zlib = require('zlib');
|
||||||
var settings = require('./Settings');
|
var settings = require('./Settings');
|
||||||
var existsSync = require('./path_exists');
|
var existsSync = require('./path_exists');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The crypto module can be absent on reduced node installations.
|
* The crypto module can be absent on reduced node installations.
|
||||||
|
@ -91,8 +92,14 @@ CachingMiddleware.prototype = new function () {
|
||||||
var supportsGzip =
|
var supportsGzip =
|
||||||
(req.get('Accept-Encoding') || '').indexOf('gzip') != -1;
|
(req.get('Accept-Encoding') || '').indexOf('gzip') != -1;
|
||||||
|
|
||||||
var path = require('url').parse(req.url).path;
|
/**
|
||||||
var cacheKey = generateCacheKey(path);
|
* `req.url` is either /file?callback=require.define&v=versionString
|
||||||
|
* or /file.
|
||||||
|
*
|
||||||
|
* invalid.invalid is just a placeholder
|
||||||
|
*/
|
||||||
|
let path = new url.URL(req.url, 'http://invalid.invalid').pathname;
|
||||||
|
let cacheKey = generateCacheKey(path);
|
||||||
|
|
||||||
fs.stat(CACHE_DIR + 'minified_' + cacheKey, function (error, stats) {
|
fs.stat(CACHE_DIR + 'minified_' + cacheKey, function (error, stats) {
|
||||||
var modifiedSince = (req.headers['if-modified-since']
|
var modifiedSince = (req.headers['if-modified-since']
|
||||||
|
|
|
@ -9,6 +9,8 @@ const settings = require('../../../src/node/utils/Settings');
|
||||||
const assert = require('assert').strict;
|
const assert = require('assert').strict;
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const queryString = require('querystring');
|
const queryString = require('querystring');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
let agent;
|
let agent;
|
||||||
|
|
||||||
|
@ -165,4 +167,20 @@ describe(__filename, function() {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
context("different callback or version parameter", function(){
|
||||||
|
it('should never create new files', async function(){
|
||||||
|
const pathToVar = path.join(__filename, '../../../../var');
|
||||||
|
|
||||||
|
// the number of files in ./var should not change during this test
|
||||||
|
const minifiedFilesBefore = (await fs.promises.readdir(pathToVar)).length;
|
||||||
|
const resource1 = "/javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define";
|
||||||
|
const resource2 = "/javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require";
|
||||||
|
const resource3 = "/javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=1234";
|
||||||
|
await agent.get(resource1);
|
||||||
|
await agent.get(resource2);
|
||||||
|
await agent.get(resource3);
|
||||||
|
const minifiedFilesAfter = (await fs.promises.readdir(pathToVar)).length;
|
||||||
|
assert.equal(minifiedFilesBefore, minifiedFilesAfter);
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue