diff --git a/source/core/options.ts b/source/core/options.ts index b8343debd..0b93beeb5 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -674,11 +674,12 @@ const defaultInternals: Options['_internals'] = { return JSON.parse(response.body as string); }, paginate: ({response}) => { - if (typeof response.headers.link !== 'string') { + const rawLinkHeader = response.headers.link; + if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') { return false; } - const parsed = parseLinkHeader(response.headers.link); + const parsed = parseLinkHeader(rawLinkHeader); const next = parsed.find(entry => entry.parameters.rel === 'next' || entry.parameters.rel === '"next"'); if (next) { diff --git a/test/pagination.ts b/test/pagination.ts index a6c7e70a9..784f1e69f 100644 --- a/test/pagination.ts +++ b/test/pagination.ts @@ -43,6 +43,18 @@ test('the link header has no next value', withServer, async (t, server, got) => t.deepEqual(received, items); }); +test('the link header is empty', withServer, async (t, server, got) => { + const items = [1]; + + server.get('/', (_request, response) => { + response.setHeader('link', ''); + response.end(JSON.stringify(items)); + }); + + const received = await got.paginate.all(''); + t.deepEqual(received, items); +}); + test('retrieves all elements', withServer, async (t, server, got) => { attachHandler(server, 2);