From 1c7b7d0fc1794c48ff3c5a406169a2acbc545f64 Mon Sep 17 00:00:00 2001 From: Jesse Brown Date: Thu, 27 Sep 2018 10:54:27 -0500 Subject: [PATCH 1/2] Fix `headers.link` not being parsed. At some point `headers.Link` became `headers.link` --- addon/adapters/github.js | 2 +- tests/unit/adapters/github-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/adapters/github.js b/addon/adapters/github.js index 7e25aee..9f1b1a2 100644 --- a/addon/adapters/github.js +++ b/addon/adapters/github.js @@ -34,7 +34,7 @@ export default RESTAdapter.extend({ // } // handleResponse(status, headers, payload, requestData) { - const linkHeader = headers.Link; + const linkHeader = headers.link; const result = this._super(status, headers, payload, requestData); if (isNone(linkHeader)) { return result; diff --git a/tests/unit/adapters/github-test.js b/tests/unit/adapters/github-test.js index 805e0ee..e2ea591 100644 --- a/tests/unit/adapters/github-test.js +++ b/tests/unit/adapters/github-test.js @@ -46,7 +46,7 @@ test('it extracts links from the Link header', function(assert) { let last = '; rel="last"'; let headers = { - Link: [first, next, prev, last].join(', ') + link: [first, next, prev, last].join(', ') }; assert.deepEqual(adapter.handleResponse(200, headers, {}, null).links, { From ab6431c1aa61e9e9535d171f2ff5094592dd762f Mon Sep 17 00:00:00 2001 From: Jesse Brown Date: Thu, 27 Sep 2018 11:49:02 -0500 Subject: [PATCH 2/2] Handle both forms of casing for Link header --- addon/adapters/github.js | 2 +- tests/unit/adapters/github-test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/addon/adapters/github.js b/addon/adapters/github.js index 9f1b1a2..6ff843e 100644 --- a/addon/adapters/github.js +++ b/addon/adapters/github.js @@ -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; diff --git a/tests/unit/adapters/github-test.js b/tests/unit/adapters/github-test.js index e2ea591..3729182 100644 --- a/tests/unit/adapters/github-test.js +++ b/tests/unit/adapters/github-test.js @@ -45,6 +45,25 @@ test('it extracts links from the Link header', function(assert) { let prev = '; rel="prev"'; let last = '; 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 extracts links from the link header', function(assert) { + let adapter = this.subject(); + let first = '; rel="first"'; + let next = '; rel="next"'; + let prev = '; rel="prev"'; + let last = '; rel="last"'; + let headers = { link: [first, next, prev, last].join(', ') };