Skip to content

Commit e9fdc4b

Browse files
committed
Standardize on parse-link-header
li.parse and parseLinkHeader accomplish the same goal. Using only one of these libraries simplifies dependencies
1 parent 1dcc902 commit e9fdc4b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/autodiscovery.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ const parseLinkHeader = require( 'parse-link-header' );
1616
* @returns {String} The URL of the located API root
1717
*/
1818
function locateAPIRootHeader( response ) {
19-
// Define the expected link rel value per http://v2.wp-api.org/guide/discovery/
20-
const rel = 'https://api.w.org/';
21-
2219
// Extract & parse the response link headers
2320
const link = response.link || ( response.headers && response.headers.link );
2421
const headers = parseLinkHeader( link );
25-
const apiHeader = headers && headers[ rel ];
22+
23+
// See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/
24+
const apiHeader = headers && headers[ 'https://api.w.org/' ];
2625

2726
if ( apiHeader && apiHeader.url ) {
2827
return apiHeader.url;

lib/http-transport.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
const agent = require( 'superagent' );
7-
const parseLinkHeader = require( 'li' ).parse;
7+
const parseLinkHeader = require( 'parse-link-header' );
88

99
const WPRequest = require( './constructors/wp-request' );
1010
const checkMethodSupport = require( './util/check-method-support' );
@@ -133,7 +133,9 @@ function createPaginationObject( result, options, httpTransport ) {
133133
}
134134

135135
// Decode the link header object
136-
const links = result.headers.link ? parseLinkHeader( result.headers.link ) : {};
136+
const links = result.headers.link ?
137+
parseLinkHeader( result.headers.link ) :
138+
{};
137139

138140
// Store pagination data from response headers on the response collection
139141
_paging = {
@@ -147,7 +149,7 @@ function createPaginationObject( result, options, httpTransport ) {
147149
_paging.next = new WPRequest( {
148150
...options,
149151
transport: httpTransport,
150-
endpoint: links.next,
152+
endpoint: links.next.url,
151153
} );
152154
}
153155

@@ -156,7 +158,7 @@ function createPaginationObject( result, options, httpTransport ) {
156158
_paging.prev = new WPRequest( {
157159
...options,
158160
transport: httpTransport,
159-
endpoint: links.prev,
161+
endpoint: links.prev.url,
160162
} );
161163
}
162164

0 commit comments

Comments
 (0)