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

Already on GitHub? Sign in to your account

Corrects bug with using compress and staticCache together. #458

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+66 −1
Split
@@ -147,7 +147,11 @@ module.exports = function staticCache(options){
// respond with cache
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
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(){
@tj

tj Jan 15, 2012

Member

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

@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.

@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);
+ })
+});