Skip to content

Commit 0a76495

Browse files
fix: match Cache-Control no-transform directive case-insensitively (#286)
Co-authored-by: Ulises Gascon <ulisesgascongonzalez@gmail.com>
1 parent c17b6e5 commit 0a76495

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎HISTORY.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Match `Cache-Control: no-transform` directive case-insensitively
5+
16
1.8.1 / 2025-07-17
27
==========
38

‎index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var hasBrotliSupport = 'createBrotliCompress' in zlib
4040
* Module variables.
4141
* @private
4242
*/
43-
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
43+
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i
4444
var SUPPORTED_ENCODING = hasBrotliSupport ? ['br', 'gzip', 'deflate', 'identity'] : ['gzip', 'deflate', 'identity']
4545
var PREFERRED_ENCODING = hasBrotliSupport ? ['br', 'gzip'] : ['gzip']
4646

‎test/compression.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,23 @@ describe('compression()', function () {
706706
.expect(200, 'hello, world', done)
707707
})
708708

709+
;['No-Transform', 'NO-TRANSFORM', 'public, No-Transform, max-age=60'].forEach(function (value) {
710+
it('should not compress response when "Cache-Control: ' + value + '"', function (done) {
711+
var server = createServer({ threshold: 0 }, function (req, res) {
712+
res.setHeader('Cache-Control', value)
713+
res.setHeader('Content-Type', 'text/plain')
714+
res.end('hello, world')
715+
})
716+
717+
request(server)
718+
.get('/')
719+
.set('Accept-Encoding', 'gzip')
720+
.expect('Cache-Control', value)
721+
.expect(shouldNotHaveHeader('Content-Encoding'))
722+
.expect(200, 'hello, world', done)
723+
})
724+
})
725+
709726
it('should not set Vary headerh', function (done) {
710727
var server = createServer({ threshold: 0 }, function (req, res) {
711728
res.setHeader('Cache-Control', 'no-transform')

0 commit comments

Comments
 (0)