Allow multiple call concatenation for res.links. Fixes #1683

This commit is contained in:
Eduardo Sorribas
2013-09-06 21:44:03 -04:00
parent e5de08faa1
commit 7059d3b71e
2 changed files with 16 additions and 1 deletions

View File

@@ -55,7 +55,9 @@ res.status = function(code){
*/
res.links = function(links){
return this.set('Link', Object.keys(links).map(function(rel){
var linkField = typeof this.get('Link') === 'undefined' ?
'' : this.get('Link') + ', ';
return this.set('Link', linkField + Object.keys(links).map(function(rel){
return '<' + links[rel] + '>; rel="' + rel + '"';
}).join(', '));
};

View File

@@ -15,5 +15,18 @@ describe('res', function(){
'<http://api.example.com/users?page=2>; rel="next", '
+ '<http://api.example.com/users?page=5>; rel="last"');
})
it('should set Link header field for multiple calls', function() {
// just one call here, because of the call on the first test
res.links({
prev: 'http://api.example.com/users?page=1',
});
res.get('link')
.should.equal(
'<http://api.example.com/users?page=2>; rel="next", '
+ '<http://api.example.com/users?page=5>; rel="last", '
+ '<http://api.example.com/users?page=1>; rel="prev"');
})
})
})