New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrects bug with using compress and staticCache together. #458

Closed
wants to merge 2 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+66 −1
Diff settings

Always

Just for now

@@ -147,7 +147,11 @@ module.exports = function staticCache(options){
// respond with cache // respond with cache
header['x-cache'] = 'HIT'; header['x-cache'] = 'HIT';
res.writeHead(200, header);
// needed to deal with compress conflict
Object.keys(header).forEach(function(field) {
res.setHeader(field, header[field]);
});
// backpressure // backpressure
function write(i) { function write(i) {
@@ -0,0 +1,61 @@
var connect = require('../');
var fixtures = __dirname + '/fixtures';
var app = connect();
app.use(connect.compress());
app.use(connect.staticCache());
app.use(connect.static(fixtures));
describe('connect.staticCache() & connect.compress()', function(){

This comment has been minimized.

@tj

tj Jan 15, 2012

Member

could we move these to test/staticCache.js as describe('Vary', or something similar

@tj

tj Jan 15, 2012

Member

could we move these to test/staticCache.js as describe('Vary', or something similar

This comment has been minimized.

@ryanrolds

ryanrolds Jan 15, 2012

Contributor

Yes, but do we want to mix the tests? Right now the test for staticCache doesn't use the compress middleware.

@ryanrolds

ryanrolds Jan 15, 2012

Contributor

Yes, but do we want to mix the tests? Right now the test for staticCache doesn't use the compress middleware.

This comment has been minimized.

@tj

tj Jan 15, 2012

Member

nvm i thought these were for negotiating via Vary at a glance

@tj

tj Jan 15, 2012

Member

nvm i thought these were for negotiating via Vary at a glance

it('should set X-Cache to MISS when missed', function(done){
app.request()
.set('Accept-Encoding', 'gzip')
.get('/todo.txt')
.expect('X-Cache', 'MISS', done);
})
it('should set X-Cache to HIT when hit', function(done){
app.request()
.set('Accept-Encoding', 'gzip')
.get('/todo.txt')
.expect('X-Cache', 'HIT', done);
})
it('should gzip files when asked', function(done){
app.request()
.get('/todo.txt')
.set('Accept-Encoding', 'gzip')
.end(function(res){
res.body.should.not.equal('- groceries');
done();
});
})
it('should not gzip files when not asked', function(done){
app.request()
.get('/todo.txt')
.expect('- groceries', done);
})
it('should set Vary', function(done){
app.request()
.get('/todo.txt')
.set('Accept-Encoding', 'gzip')
.expect('Vary', 'Accept-Encoding', done);
})
it('should set Vary at all times', function(done){
app.request()
.get('/todo.txt')
.expect('Vary', 'Accept-Encoding', done);
})
it('should set Content-Encoding', function(done){
app.request()
.get('/todo.txt')
.set('Accept-Encoding', 'gzip')
.expect('Content-Encoding', 'gzip', done);
})
});
ProTip! Use n and p to navigate between commits in a pull request.