Skip to content
Myr

Fixed `res.send()` freshness check, respect res.statusCode

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

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent f90401b · Browse files · 2 files+23 added−2 removed
This commit

State

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

Diff stats

2 files+23 added−2 removed

  • tests:+20 added−1 removed
  • other:+3 added−1 removed

2 files+23 added−2 removed

modified:lib/response.js+3 added-1 removed
111 unmodified lines
112 : crc.crc32(body));113 }114115 // freshness116 if ((this.statusCode >= 200 && this.statusCode < 300) || this.statusCode === 304) {116 if (req.fresh) this.statusCode = 304;117 if (req.fresh) this.statusCode = 304;118 }119120 // strip irrelevant headers121 if (204 == this.statusCode || 304 == this.statusCode) {122 this.removeHeader('Content-Type');
529 unmodified lines
modified:test/res.send.js+20 added-1 removed
284 unmodified lines
285 })286 })287 })288289 it('should always check freshness', function(done){289 it('should always check regardless of length', function(done){290 var app = express();291292 app.use(function(req, res, next){293 res.set('ETag', 'asdf');
18 unmodified lines
312 .get('/')313 .set('If-None-Match', '-1498647312')314 .expect(304, done);315 })316317 it('should not perform freshness check unless 2xx or 304', function(done){318 var app = express();319320 app.use(function(req, res, next){321 res.status(500);322 res.set('ETag', 'asdf');323 res.send('hey');324 });325326 request(app)327 .get('/')328 .set('If-None-Match', 'asdf')329 .end(function(res){330 res.should.have.status(500);331 res.body.should.equal('hey');332 done();333 });334 })335})