mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 16:36:15 -04:00
minify: Fix gzip not triggered for packages (#4491)
* caching_middleware: fix gzip compression not triggered * packages: If a client sets `Accept-Encoding: gzip`, the responseCache will include `Content-Encoding: gzip` in all future responses, even if a subsequent request does not set `Accept-Encoding` or another client requests the file without setting `Accept-Encoding`. Fix that. * caching_middleware: use `test` instead of `match` * add tests * make code easier to understand * make the regex more clear
This commit is contained in:
parent
1d491c0059
commit
f2febcfc7e
2 changed files with 171 additions and 3 deletions
|
@ -20,7 +20,6 @@ var fs = require('fs');
|
|||
var path = require('path');
|
||||
var zlib = require('zlib');
|
||||
var settings = require('./Settings');
|
||||
var semver = require('semver');
|
||||
var existsSync = require('./path_exists');
|
||||
|
||||
/*
|
||||
|
@ -192,11 +191,12 @@ CachingMiddleware.prototype = new function () {
|
|||
res.write = old_res.write || res.write;
|
||||
res.end = old_res.end || res.end;
|
||||
|
||||
var headers = responseCache[cacheKey].headers;
|
||||
let headers = {};
|
||||
Object.assign(headers, (responseCache[cacheKey].headers || {}));
|
||||
var statusCode = responseCache[cacheKey].statusCode;
|
||||
|
||||
var pathStr = CACHE_DIR + 'minified_' + cacheKey;
|
||||
if (supportsGzip && (headers['content-type'] || '').match(/^text\//)) {
|
||||
if (supportsGzip && /application\/javascript/.test(headers['content-type'])) {
|
||||
pathStr = pathStr + '.gz';
|
||||
headers['content-encoding'] = 'gzip';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue