Skip to content

Commit

Permalink
Merge pull request #196 from jabrown85/fix-for-header-link
Browse files Browse the repository at this point in the history
Fix `headers.link` not being parsed.
  • Loading branch information
elwayman02 authored Sep 27, 2018
2 parents 7029f7f + ab6431c commit d3e3551
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/adapters/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default RESTAdapter.extend({
// }
//
handleResponse(status, headers, payload, requestData) {
const linkHeader = headers.Link;
const linkHeader = headers.link || headers.Link;
const result = this._super(status, headers, payload, requestData);
if (isNone(linkHeader)) {
return result;
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/adapters/github-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ test('it extracts links from the Link header', function(assert) {
});
});

test('it extracts links from the link header', function(assert) {
let adapter = this.subject();
let first = '<https://api.github.com/resouce?page=1&per_page=5>; rel="first"';
let next = '<https://api.github.com/resouce?page=3&per_page=5>; rel="next"';
let prev = '<https://api.github.com/resouce?page=1&per_page=5>; rel="prev"';
let last = '<https://api.github.com/resouce?page=4&per_page=5>; rel="last"';

let headers = {
link: [first, next, prev, last].join(', ')
};

assert.deepEqual(adapter.handleResponse(200, headers, {}, null).links, {
first: 'https://api.github.com/resouce?page=1&per_page=5',
next: 'https://api.github.com/resouce?page=3&per_page=5',
prev: 'https://api.github.com/resouce?page=1&per_page=5',
last: 'https://api.github.com/resouce?page=4&per_page=5'
});
});

test('it handles a missing Link header', function(assert) {
let adapter = this.subject();
let headers = {};
Expand Down

0 comments on commit d3e3551

Please sign in to comment.