Add X-Count header when slicing collection

This commit is contained in:
Emmanuel Quentin
2014-08-26 13:35:15 +02:00
parent 96f2112231
commit daf3da70e0
2 changed files with 13 additions and 6 deletions

View File

@ -36,6 +36,9 @@ routes.list = function(req, res, next) {
} }
if (_start) { if (_start) {
res.setHeader('X-Count', resource.length)
res.setHeader('Access-Control-Expose-Headers', 'X-Count')
resource = resource.slice(_start, _end) resource = resource.slice(_start, _end)
} }

View File

@ -61,7 +61,11 @@ describe('Server', function() {
.get('/comments?_start=1&_end=2') .get('/comments?_start=1&_end=2')
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(low.db.comments.slice(1, 2)) .expect(low.db.comments.slice(1, 2))
.expect(200, done) .expect(200)
.end(function(err, res){
assert.equal(res.headers['x-count'], 5)
done()
})
}) })
}) })