Permalink
Browse files

Merge pull request #1694 from kavu/add_disable_etag

Add application setting to disable ETag (again)
  • Loading branch information...
2 parents 6942070 + 54a192a commit 610e172fcf9306bd5812bb2bae8904c23e0e8043 @tj tj committed Aug 2, 2013
Showing with 63 additions and 1 deletion.
  1. +1 −0 lib/application.js
  2. +4 −1 lib/response.js
  3. +58 −0 test/res.send.js
View
@@ -46,6 +46,7 @@ app.init = function(){
app.defaultConfiguration = function(){
// default settings
this.enable('x-powered-by');
+ this.enable('etag');
this.set('env', process.env.NODE_ENV || 'development');
this.set('subdomain offset', 2);
debug('booting in %s mode', this.get('env'));
View
@@ -82,6 +82,9 @@ res.send = function(body){
var head = 'HEAD' == req.method;
var len;
+ // settings
+ var app = this.app;
+
// allow status / body
if (2 == arguments.length) {
// res.send(body, status) backwards compat
@@ -128,7 +131,7 @@ res.send = function(body){
// ETag support
// TODO: W/ support
- if (len > 1024 && 'GET' == req.method) {
+ if (app.settings['etag'] && len > 1024 && 'GET' == req.method) {
if (!this.get('ETag')) {
this.set('ETag', etag(body));
}
View
@@ -318,4 +318,62 @@ describe('res', function(){
.get('/?callback=foo')
.expect('{"foo":"bar"}', done);
})
+
+ describe('"etag" setting', function(){
+ describe('when enabled', function(){
+ it('should send ETag ', function(done){
+ var app = express();
+
+ app.use(function(req, res){
+ var str = Array(1024 * 2).join('-');
+ res.send(str);
+ });
+
+ request(app)
+ .get('/')
+ .end(function(err, res){
+ res.headers.should.have.property('etag', '"-1498647312"');
+ done();
+ });
+ });
+ });
+
+ describe('when disabled', function(){
+ it('should send no ETag', function(done){
+ var app = express();
+
+ app.use(function(req, res){
+ var str = Array(1024 * 2).join('-');
+ res.send(str);
+ });
+
+ app.disable('etag');
+
+ request(app)
+ .get('/')
+ .end(function(err, res){
+ res.headers.should.not.have.property('etag');
+ done();
+ });
+ });
+
+ it('should send ETag when manually set', function(done){
+ var app = express();
+
+ app.disable('etag');
+
+ app.use(function(req, res){
+ res.set('etag', 1);
+ res.send(200);
+ });
+
+ request(app)
+ .get('/')
+ .end(function(err, res){
+ res.headers.should.have.property('etag');
+ done();
+ });
+ });
+ });
+ })
})

1 comment on commit 610e172

Please sign in to comment.