{"id":"765a8c6431dc36c0","repo":"sindresorhus/got","slug":"invalid-format-of-the-link-header-reference-tri","errorCode":null,"errorMessage":"Invalid format of the Link header reference: ${trimmedUriReference}","messagePattern":"Invalid format of the Link header reference: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/core/parse-link-header.ts","lineNumber":70,"sourceCode":"\t}\n\n\tvalues.push(current);\n\treturn values;\n};\n\nexport default function parseLinkHeader(link: string) {\n\tconst parsed = [];\n\n\tconst items = splitHeaderValue(link, ',');\n\n\tfor (const item of items) {\n\t\t// https://tools.ietf.org/html/rfc5988#section-5\n\t\tconst [rawUriReference, ...rawLinkParameters] = splitHeaderValue(item, ';') as [string, ...string[]];\n\t\tconst trimmedUriReference = rawUriReference.trim();\n\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with\n\t\tif (trimmedUriReference[0] !== '<' || trimmedUriReference.at(-1) !== '>') {\n\t\t\tthrow new Error(`Invalid format of the Link header reference: ${trimmedUriReference}`);\n\t\t}\n\n\t\tconst reference = trimmedUriReference.slice(1, -1);\n\t\tconst parameters: Record<string, string> = {};\n\n\t\tif (reference.includes('<') || reference.includes('>')) {\n\t\t\tthrow new Error(`Invalid format of the Link header reference: ${trimmedUriReference}`);\n\t\t}\n\n\t\tif (rawLinkParameters.length === 0) {\n\t\t\tthrow new Error(`Unexpected end of Link header parameters: ${rawLinkParameters.join(';')}`);\n\t\t}\n\n\t\tfor (const rawParameter of rawLinkParameters) {\n\t\t\tconst trimmedRawParameter = rawParameter.trim();\n\t\t\tconst center = trimmedRawParameter.indexOf('=');\n\n\t\t\tif (center === -1) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/core/parse-link-header.ts#L52-L88","documentation":"parse-link-header.ts:70 enforces RFC 8288: each link reference must be wrapped in angle brackets, e.g. `</path>; rel=\"next\"`. If the first non-whitespace char is not `<` or the last is not `>`, the parser refuses it. This prevents silently producing a bogus `reference` and downstream URL-resolution bugs.","triggerScenarios":"A `Link` header value like `/page2; rel=\"next\"` (missing angle brackets), `</page2; rel=\"next\"` (missing closing bracket), or whitespace-corrupted references. Fires inside the per-item loop of `parseLinkHeader`.","commonSituations":"Custom server code that builds Link headers via string concatenation without the `<>` wrapping; a reverse proxy stripping angle brackets; copy-paste from a spec example that dropped the brackets; servers emitting relative references without brackets.","solutions":["Ensure every link reference in the upstream `Link` header is wrapped as `<URI-reference>`.","If you control the server, use a Link-header builder library instead of string concatenation.","If you cannot fix the server, pre-process the header to wrap bare references before passing to Got (or disable link pagination).","Verify with `curl -i` that the raw header bytes match RFC 8288."],"exampleFix":"// before: upstream sends  Link: /page2; rel=\"next\"\n\n// after: upstream sends   Link: </page2>; rel=\"next\"","handlingStrategy":"validation","validationCode":"function isValidReference(item) {\n  const ref = item.split(';')[0].trim();\n  return ref.startsWith('<') && ref.endsWith('>');\n}\nconst ok = (response.headers.link ?? '').split(',').every(isValidReference);","typeGuard":"const isBracketedReference = (s: string): boolean =>\n  s.trim().startsWith('<') && s.trim().endsWith('>');","tryCatchPattern":null,"preventionTips":["Validate Link-header shape before relying on it for pagination.","Use an RFC 8288-compliant Link builder on the server side.","Capture and round-trip-test the server's Link header in integration tests.","Disable link pagination for endpoints known to emit non-compliant headers."],"tags":["link-header","parsing","pagination","rfc-8288"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}