diff --git a/lib/response.js b/lib/response.js index 0d0f6956..a10ab9b1 100644 --- a/lib/response.js +++ b/lib/response.js @@ -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(', ')); }; diff --git a/test/res.links.js b/test/res.links.js index 455e58c6..76cb4941 100644 --- a/test/res.links.js +++ b/test/res.links.js @@ -15,5 +15,18 @@ describe('res', function(){ '; rel="next", ' + '; 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( + '; rel="next", ' + + '; rel="last", ' + + '; rel="prev"'); + }) }) })