Skip to content

Commit fc3c380

Browse files
committed
Add safeguard against unexpected response header capitalization
May address #332
1 parent 95df17a commit fc3c380

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/http-transport.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,24 @@ function extractResponseBody( response ) {
120120
function createPaginationObject( result, options, httpTransport ) {
121121
let _paging = null;
122122

123-
if ( ! result.headers || ! result.headers[ 'x-wp-totalpages' ] ) {
123+
if ( ! result.headers ) {
124124
// No headers: return as-is
125125
return _paging;
126126
}
127127

128+
// Guard against capitalization inconsistencies in returned headers
129+
Object.keys( result.headers ).forEach( ( header ) => {
130+
result.headers[ header.toLowerCase() ] = result.headers[ header ];
131+
} );
132+
133+
if ( ! result.headers[ 'x-wp-totalpages' ] ) {
134+
// No paging: return as-is
135+
return _paging;
136+
}
137+
128138
const totalPages = +result.headers[ 'x-wp-totalpages' ];
129139

130-
if ( ! totalPages || totalPages === '0' ) {
140+
if ( ! totalPages || totalPages === 0 ) {
131141
// No paging: return as-is
132142
return _paging;
133143
}

0 commit comments

Comments
 (0)