sindresorhus/got · error · Error
Failed to parse Link header: ${link}
Error message
Failed to parse Link header: ${link} What it means
parse-link-header.ts:89: each `;`-separated link parameter must be a `name=value` pair. If a parameter has no `=` (e.g. `</p>; relnext` or `</p>; rel`), `indexOf('=')` returns -1 and Got throws with the full original `link` header in the message for context.
Source
Thrown at source/core/parse-link-header.ts:89
}
const reference = trimmedUriReference.slice(1, -1);
const parameters: Record<string, string> = {};
if (reference.includes('<') || reference.includes('>')) {
throw new Error(`Invalid format of the Link header reference: ${trimmedUriReference}`);
}
if (rawLinkParameters.length === 0) {
throw new Error(`Unexpected end of Link header parameters: ${rawLinkParameters.join(';')}`);
}
for (const rawParameter of rawLinkParameters) {
const trimmedRawParameter = rawParameter.trim();
const center = trimmedRawParameter.indexOf('=');
if (center === -1) {
throw new Error(`Failed to parse Link header: ${link}`);
}
const name = trimmedRawParameter.slice(0, center).trim();
const value = trimmedRawParameter.slice(center + 1).trim();
parameters[name] = value;
}
parsed.push({
reference,
parameters,
});
}
return parsed;
}
View on GitHub (pinned to e3924aa1e5)
Solutions
- Ensure every parameter after the reference is `name=value` (quoted value if it contains special chars).
- Inspect the raw header and fix the malformed parameter on the server.
- If the upstream cannot be fixed, disable link-based pagination for that endpoint.
- Add a server-side unit test that round-trips the Link header through an RFC 8288 parser.
Example fix
// before: upstream sends Link: </p2>; rel="next"; bogus // after: upstream sends Link: </p2>; rel="next"; title="bogus"
Defensive patterns
Strategy: validation
Validate before calling
function paramsHaveEquals(item) {
return item.split(';').slice(1).every(p => p.includes('='));
}
const ok = (response.headers.link ?? '').split(',').every(paramsHaveEquals); Type guard
const linkParamsWellFormed = (s: string): boolean =>
s.split(';').slice(1).every(p => p.trim().includes('=')); Prevention
- Build Link parameters as `name=value` pairs only.
- Round-trip-test server Link headers through a parser.
- Disable pagination for endpoints with non-RFC8288 link syntax.
- Capture raw headers when diagnosing pagination failures.
When it happens
Trigger: A `Link` header like `</page2>; rel="next"; bogus` (last parameter has no `=`), or `</page2>; next` (bare token). Distinct from 47–49 (which validate structure of the reference); this validates parameter syntax.
Common situations: A server concatenating parameters with malformed separators; an extension parameter written as a bare token instead of `name=value`; hand-built test fixtures with typos; an upstream that appends a flag-like parameter.
Related errors
- Invalid format of the Link header reference: ${trimmedUriRef
- Unexpected end of Link header parameters: ${rawLinkParameter
- Failed to parse Link header: ${value}
- `url` protocol must be followed by `//`
AI-assisted analysis of sindresorhus/got@e3924aa1e5 (2026-08-03).
Data as JSON: /data/errors/2f7c7f6f99a2e233.json.
Report an issue: GitHub.