sindresorhus/got · error · Error

Invalid format of the Link header reference: ${trimmedUriRef

Error message

Invalid format of the Link header reference: ${trimmedUriReference}

What it means

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.

Source

Thrown at source/core/parse-link-header.ts:70

	}

	values.push(current);
	return values;
};

export default function parseLinkHeader(link: string) {
	const parsed = [];

	const items = splitHeaderValue(link, ',');

	for (const item of items) {
		// https://tools.ietf.org/html/rfc5988#section-5
		const [rawUriReference, ...rawLinkParameters] = splitHeaderValue(item, ';') as [string, ...string[]];
		const trimmedUriReference = rawUriReference.trim();

		// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
		if (trimmedUriReference[0] !== '<' || trimmedUriReference.at(-1) !== '>') {
			throw new Error(`Invalid format of the Link header reference: ${trimmedUriReference}`);
		}

		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) {

View on GitHub (pinned to e3924aa1e5)

Solutions

  1. Ensure every link reference in the upstream `Link` header is wrapped as `<URI-reference>`.
  2. If you control the server, use a Link-header builder library instead of string concatenation.
  3. If you cannot fix the server, pre-process the header to wrap bare references before passing to Got (or disable link pagination).
  4. Verify with `curl -i` that the raw header bytes match RFC 8288.

Example fix

// before: upstream sends  Link: /page2; rel="next"

// after: upstream sends   Link: </page2>; rel="next"
Defensive patterns

Strategy: validation

Validate before calling

function isValidReference(item) {
  const ref = item.split(';')[0].trim();
  return ref.startsWith('<') && ref.endsWith('>');
}
const ok = (response.headers.link ?? '').split(',').every(isValidReference);

Type guard

const isBracketedReference = (s: string): boolean =>
  s.trim().startsWith('<') && s.trim().endsWith('>');

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Related errors


AI-assisted analysis of sindresorhus/got@e3924aa1e5 (2026-08-03). Data as JSON: /data/errors/765a8c6431dc36c0.json. Report an issue: GitHub.