Skip to content

Corrects bug with using compress and staticCache together. #458

Closed
wants to merge 2 commits into from
View
6 lib/middleware/staticCache.js
@@ -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) {
View
61 test/staticCacheCompress.js
@@ -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
Sencha Labs member
tj added a note Jan 15, 2012

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

@ryanrolds
ryanrolds added a note Jan 15, 2012

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

@tj
Sencha Labs member
tj added a note Jan 15, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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);
+ })
+});
Something went wrong with that request. Please try again.