Skip to content

Commit b5718b6

Browse files
author
Mikko Tiihonen
committed
Append to existing Vary header if it exists
1 parent f573b07 commit b5718b6

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,11 @@ SendStream.prototype.sendFile = function sendFile(path) {
694694
}
695695

696696
function sendPreferredContent(p, stat, contents) {
697-
if (contents.length) self.res.setHeader('Vary', 'Accept-Encoding')
697+
if (contents.length) {
698+
var old = self.res.getHeader('Vary')
699+
var value = (old ? old + ', ' : '') + 'Accept-Encoding'
700+
self.res.setHeader('Vary', value)
701+
}
698702

699703
var preferredContent
700704
var extensions = self.getAcceptEncodingExtensions()

test/send.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,16 @@ describe('send(file, options)', function(){
11741174
.set('Accept-Encoding', 'gzip')
11751175
.expect('Content-Length', '11', done)
11761176
})
1177+
1178+
it('should append to existing Vary header', function(done){
1179+
var app = http.createServer(function(req, res){
1180+
res.setHeader('Vary', 'custom')
1181+
send(req, req.url, {precompressed: true, root: fixtures}).pipe(res)
1182+
});
1183+
request(app)
1184+
.get('/name.html')
1185+
.expect('Vary', 'custom, Accept-Encoding', done);
1186+
})
11771187
})
11781188

11791189
describe('index', function(){

0 commit comments

Comments
 (0)