mirror of
https://github.com/zebrajr/express.git
synced 2026-01-15 12:15:27 +00:00
Allow multiple call concatenation for res.links. Fixes #1683
This commit is contained in:
@@ -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(', '));
|
||||
};
|
||||
|
||||
@@ -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"');
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user