parseHeader(text: string): { name: string; value: string; } | null
A header as it was typed, or null where that is not a header at all.
Both spellings, because both hands type both: accept=application/json is what you write when
you are assigning something, and accept: application/json is what you get when you copy a line
out of a response. Whichever separator comes FIRST is the separator, which is what makes
content-type: text/html; charset=utf-8 land the way it reads rather than splitting on the
charset=.
The name is lower-cased because HTTP does not distinguish, and a session that thought
Accept and accept were two headers would send both.
import { parseHeader } from './http-service.ts'; parseHeader('Accept=application/json'); // { name: 'accept', value: 'application/json' } parseHeader('content-type: text/html; charset=utf-8')?.value; // 'text/html; charset=utf-8' parseHeader('accept'); // null — nothing assigned parseHeader('bad header=x'); // null — a space is not allowed in a header name