Skip to content

Commit eb38e9b

Browse files
committed
tests: expand the conditional-GET tests
1 parent 4568381 commit eb38e9b

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

test/send.js

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -403,50 +403,80 @@ describe('send(file).pipe(res)', function () {
403403
})
404404

405405
describe('with conditional-GET', function () {
406-
it('should respond with 304 on a match', function (done) {
407-
request(app)
406+
it('should remove Content headers with 304', function (done) {
407+
var server = createServer({root: fixtures}, function (req, res) {
408+
res.setHeader('Content-Language', 'en-US')
409+
res.setHeader('Content-Location', 'http://localhost/name.txt')
410+
res.setHeader('Contents', 'foo')
411+
})
412+
413+
request(server)
408414
.get('/name.txt')
409415
.expect(200, function (err, res) {
410416
if (err) return done(err)
411-
request(app)
417+
request(server)
412418
.get('/name.txt')
413419
.set('If-None-Match', res.headers.etag)
420+
.expect(shouldNotHaveHeader('Content-Language'))
421+
.expect(shouldNotHaveHeader('Content-Length'))
422+
.expect(shouldNotHaveHeader('Content-Type'))
423+
.expect('Content-Location', 'http://localhost/name.txt')
424+
.expect('Contents', 'foo')
414425
.expect(304, done)
415426
})
416427
})
417428

418-
it('should respond with 200 otherwise', function (done) {
419-
request(app)
420-
.get('/name.txt')
421-
.expect(200, function (err, res) {
422-
if (err) return done(err)
429+
describe('where "If-Modified-Since" is set', function () {
430+
it('should respond with 304 when unmodified', function (done) {
423431
request(app)
424432
.get('/name.txt')
425-
.set('If-None-Match', '"123"')
426-
.expect(200, 'tobi', done)
433+
.expect(200, function (err, res) {
434+
if (err) return done(err)
435+
request(app)
436+
.get('/name.txt')
437+
.set('If-Modified-Since', res.headers['last-modified'])
438+
.expect(304, done)
439+
})
440+
})
441+
442+
it('should respond with 200 when modified', function (done) {
443+
request(app)
444+
.get('/name.txt')
445+
.expect(200, function (err, res) {
446+
if (err) return done(err)
447+
var lmod = new Date(res.headers['last-modified'])
448+
var date = new Date(lmod - 60000)
449+
request(app)
450+
.get('/name.txt')
451+
.set('If-Modified-Since', date.toUTCString())
452+
.expect(200, 'tobi', done)
453+
})
427454
})
428455
})
429456

430-
it('should remove Content headers', function (done) {
431-
var app = createServer({root: fixtures}, function (req, res) {
432-
res.setHeader('Content-Language', 'en-US')
433-
res.setHeader('Content-Location', 'http://localhost/name.txt')
434-
res.setHeader('Contents', 'foo')
457+
describe('where "If-None-Match" is set', function () {
458+
it('should respond with 304 when ETag matched', function (done) {
459+
request(app)
460+
.get('/name.txt')
461+
.expect(200, function (err, res) {
462+
if (err) return done(err)
463+
request(app)
464+
.get('/name.txt')
465+
.set('If-None-Match', res.headers.etag)
466+
.expect(304, done)
467+
})
435468
})
436469

437-
request(app)
438-
.get('/name.txt')
439-
.expect(200, function (err, res) {
440-
if (err) return done(err)
470+
it('should respond with 200 when ETag unmatched', function (done) {
441471
request(app)
442472
.get('/name.txt')
443-
.set('If-None-Match', res.headers.etag)
444-
.expect(shouldNotHaveHeader('Content-Language'))
445-
.expect(shouldNotHaveHeader('Content-Length'))
446-
.expect(shouldNotHaveHeader('Content-Type'))
447-
.expect('Content-Location', 'http://localhost/name.txt')
448-
.expect('Contents', 'foo')
449-
.expect(304, done)
473+
.expect(200, function (err, res) {
474+
if (err) return done(err)
475+
request(app)
476+
.get('/name.txt')
477+
.set('If-None-Match', '"123"')
478+
.expect(200, 'tobi', done)
479+
})
450480
})
451481
})
452482
})

0 commit comments

Comments
 (0)