From 0af2a9aebcd12861b7c75ae68b54851944ffb9e5 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Tue, 21 Jan 2025 10:18:02 -0500 Subject: [PATCH] fix: don't handle * in enforceEncoding (#213) --- .github/workflows/ci.yml | 1 + index.js | 4 ++-- test/compression.js | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d03534f..45655c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,7 @@ jobs: test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: name: - Node.js 0.8 diff --git a/index.js b/index.js index 198c85b..c0638e0 100644 --- a/index.js +++ b/index.js @@ -44,7 +44,7 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/ var SUPPORTED_ENCODING = hasBrotliSupport ? ['br', 'gzip', 'deflate', 'identity'] : ['gzip', 'deflate', 'identity'] var PREFERRED_ENCODING = hasBrotliSupport ? ['br', 'gzip'] : ['gzip'] -var encodingSupported = ['*', 'gzip', 'deflate', 'identity', 'br'] +var encodingSupported = ['gzip', 'deflate', 'identity', 'br'] /** * Compress response data with gzip / deflate. @@ -200,7 +200,7 @@ function compression (options) { // if no method is found, use the default encoding if (!req.headers['accept-encoding'] && encodingSupported.indexOf(enforceEncoding) !== -1) { - method = enforceEncoding === '*' ? 'gzip' : enforceEncoding + method = enforceEncoding } // negotiation failed diff --git a/test/compression.js b/test/compression.js index c2c1115..8107def 100644 --- a/test/compression.js +++ b/test/compression.js @@ -960,7 +960,7 @@ describe('compression()', function () { .expect(200, 'hello, world', done) }) - it('should be gzip if no accept-encoding is sent when enforceEncoding is *', function (done) { + it('should not compress when enforceEnconding is *', function (done) { var server = createServer({ threshold: 0, enforceEncoding: '*' }, function (req, res) { res.setHeader('Content-Type', 'text/plain') res.end('hello, world') @@ -969,8 +969,8 @@ describe('compression()', function () { request(server) .get('/') .set('Accept-Encoding', '') - .expect('Content-Encoding', 'gzip') - .expect(200, 'hello, world', done) + .expect(shouldNotHaveHeader('Content-Encoding')) + .expect(200, done) }) }) })