Skip to content

Commit

Permalink
Don't encode responses with Cache-Control: no-transform
Browse files Browse the repository at this point in the history
  • Loading branch information
glenjamin committed Sep 8, 2015
1 parent c2af8bd commit 70c5f8b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ function compression(options) {
return
}

// Don't compress for Cache-Control: no-transform
// https://tools.ietf.org/html/rfc7234#section-5.2.1.6
var cacheControl = res.getHeader('Cache-Control') || ''
if (cacheControl.match(/\bno-transform\b/)) {
nocompress('no-transform')
return
}

// vary
vary(res, 'Accept-Encoding')

Expand Down
14 changes: 14 additions & 0 deletions test/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ describe('compression()', function(){
.expect(200, done)
})

it('should skip Cache-Control: no-transform', function(done){
var server = createServer({ threshold: 0 }, function (req, res) {
res.setHeader('Content-Type', 'text/plain')
res.setHeader('Cache-Control', 'no-transform')
res.end('hello, world')
})

request(server)
.get('/')
.set('Accept-Encoding', 'gzip')
.expect(shouldNotHaveHeader('Content-Encoding'))
.expect(200, done)
})

it('should skip unknown accept-encoding', function(done){
var server = createServer({ threshold: 0 }, function (req, res) {
res.setHeader('Content-Type', 'text/plain')
Expand Down

0 comments on commit 70c5f8b

Please sign in to comment.