From bf771a5cc781b9c58a316e32ec8fcb8b1175e437 Mon Sep 17 00:00:00 2001 From: vaibhavmashal Date: Mon, 31 Aug 2026 22:00:12 +0530 Subject: [PATCH 1/3] fix: match Cache-Control no-transform directive case-insensitively --- index.js | 2 +- test/compression.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c0638e08..5739707f 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ var hasBrotliSupport = 'createBrotliCompress' in zlib * Module variables. * @private */ -var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/ +var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i var SUPPORTED_ENCODING = hasBrotliSupport ? ['br', 'gzip', 'deflate', 'identity'] : ['gzip', 'deflate', 'identity'] var PREFERRED_ENCODING = hasBrotliSupport ? ['br', 'gzip'] : ['gzip'] diff --git a/test/compression.js b/test/compression.js index 8107def0..b6399ef4 100644 --- a/test/compression.js +++ b/test/compression.js @@ -706,6 +706,36 @@ describe('compression()', function () { .expect(200, 'hello, world', done) }) + it('should not compress response when casing is "No-Transform"', function (done) { + var server = createServer({ threshold: 0 }, function (req, res) { + res.setHeader('Cache-Control', 'No-Transform') + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) + + request(server) + .get('/') + .set('Accept-Encoding', 'gzip') + .expect('Cache-Control', 'No-Transform') + .expect(shouldNotHaveHeader('Content-Encoding')) + .expect(200, 'hello, world', done) + }) + + it('should not compress response when casing is "NO-TRANSFORM"', function (done) { + var server = createServer({ threshold: 0 }, function (req, res) { + res.setHeader('Cache-Control', 'NO-TRANSFORM') + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) + + request(server) + .get('/') + .set('Accept-Encoding', 'gzip') + .expect('Cache-Control', 'NO-TRANSFORM') + .expect(shouldNotHaveHeader('Content-Encoding')) + .expect(200, 'hello, world', done) + }) + it('should not set Vary headerh', function (done) { var server = createServer({ threshold: 0 }, function (req, res) { res.setHeader('Cache-Control', 'no-transform') From 38e7546c6a8d685cae3af41773c45f13371f906e Mon Sep 17 00:00:00 2001 From: Ulises Gascon Date: Wed, 9 Sep 2026 11:55:08 +0200 Subject: [PATCH 2/3] test: loop no-transform casing cases --- test/compression.js | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/test/compression.js b/test/compression.js index b6399ef4..cf15f987 100644 --- a/test/compression.js +++ b/test/compression.js @@ -706,34 +706,21 @@ describe('compression()', function () { .expect(200, 'hello, world', done) }) - it('should not compress response when casing is "No-Transform"', function (done) { - var server = createServer({ threshold: 0 }, function (req, res) { - res.setHeader('Cache-Control', 'No-Transform') - res.setHeader('Content-Type', 'text/plain') - res.end('hello, world') - }) - - request(server) - .get('/') - .set('Accept-Encoding', 'gzip') - .expect('Cache-Control', 'No-Transform') - .expect(shouldNotHaveHeader('Content-Encoding')) - .expect(200, 'hello, world', done) - }) + ;['No-Transform', 'NO-TRANSFORM', 'public, No-Transform, max-age=60'].forEach(function (value) { + it('should not compress response when "Cache-Control: ' + value + '"', function (done) { + var server = createServer({ threshold: 0 }, function (req, res) { + res.setHeader('Cache-Control', value) + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) - it('should not compress response when casing is "NO-TRANSFORM"', function (done) { - var server = createServer({ threshold: 0 }, function (req, res) { - res.setHeader('Cache-Control', 'NO-TRANSFORM') - res.setHeader('Content-Type', 'text/plain') - res.end('hello, world') + request(server) + .get('/') + .set('Accept-Encoding', 'gzip') + .expect('Cache-Control', value) + .expect(shouldNotHaveHeader('Content-Encoding')) + .expect(200, 'hello, world', done) }) - - request(server) - .get('/') - .set('Accept-Encoding', 'gzip') - .expect('Cache-Control', 'NO-TRANSFORM') - .expect(shouldNotHaveHeader('Content-Encoding')) - .expect(200, 'hello, world', done) }) it('should not set Vary headerh', function (done) { From 0f54fb750a97dbf6af12b1e838b4f1ea98f331fb Mon Sep 17 00:00:00 2001 From: Ulises Gascon Date: Wed, 9 Sep 2026 11:55:12 +0200 Subject: [PATCH 3/3] docs: history entry for no-transform fix --- HISTORY.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 0678bf2a..43c0d4b9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Match `Cache-Control: no-transform` directive case-insensitively + 1.8.1 / 2025-07-17 ==========