Skip to content
Myr

Add application setting to disable ETag completely

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Max Riveiro · committed by Max Riveiro · parent c3bd65e · Browse files · 3 files+63 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+63 added−1 removed

  • tests:+58 added−0 removed
  • other:+5 added−1 removed

3 files+63 added−1 removed

modified:lib/application.js+1 added
44 unmodified lines
4546app.defaultConfiguration = function(){47 // default settings48 this.enable('x-powered-by');49 this.enable('etag');50 this.set('env', process.env.NODE_ENV || 'development');51 this.set('subdomain offset', 2);52 debug('booting in %s mode', this.get('env'));53
483 unmodified lines
modified:lib/response.js+4 added-1 removed
80 unmodified lines
81 var req = this.req;82 var head = 'HEAD' == req.method;83 var len;8485 // settings86 var app = this.app;8788 // allow status / body89 if (2 == arguments.length) {90 // res.send(body, status) backwards compat91 if ('number' != typeof body && 'number' == typeof arguments[1]) {
38 unmodified lines
130 }131132 // ETag support133 // TODO: W/ support131 if (len > 1024 && 'GET' == req.method) {134 if (app.settings['etag'] && len > 1024 && 'GET' == req.method) {135 if (!this.get('ETag')) {136 this.set('ETag', etag(body));137 }138 }
622 unmodified lines
modified:test/res.send.js+58 added
316 unmodified lines
317 request(app)318 .get('/?callback=foo')319 .expect('{"foo":"bar"}', done);320 })321322 describe('"etag" setting', function(){323 describe('when enabled', function(){324 it('should send ETag ', function(done){325 var app = express();326327 app.use(function(req, res){328 var str = Array(1024 * 2).join('-');329 res.send(str);330 });331332 request(app)333 .get('/')334 .end(function(err, res){335 res.headers.should.have.property('etag', '"-1498647312"');336 done();337 });338 });339 });340341 describe('when disabled', function(){342 it('should send no ETag', function(done){343 var app = express();344345 app.use(function(req, res){346 var str = Array(1024 * 2).join('-');347 res.send(str);348 });349350 app.disable('etag');351352 request(app)353 .get('/')354 .end(function(err, res){355 res.headers.should.not.have.property('etag');356 done();357 });358 });359360 it('should send ETag when manually set', function(done){361 var app = express();362363 app.disable('etag');364365 app.use(function(req, res){366 res.set('etag', 1);367 res.send(200);368 });369370 request(app)371 .get('/')372 .end(function(err, res){373 res.headers.should.have.property('etag');374 done();375 });376 });377 });378 })379})