32 lines
1.7 KiB
Plaintext
32 lines
1.7 KiB
Plaintext
/**
|
|
* Extracts the media type (the lowercased `type/subtype` pair, without
|
|
* parameters) from a raw `Content-Type` header value, or `undefined` when the
|
|
* header is missing or empty.
|
|
*
|
|
* Content-Type comparisons must use the parsed media type, never a substring
|
|
* search of the raw header: a value like `text/plain; a=application/json`
|
|
* contains the substring `application/json` but its media type is
|
|
* `text/plain`, and case variants or parameters make naive string comparison
|
|
* wrong in both directions.
|
|
*
|
|
* "Essence" is the WHATWG MIME Sniffing standard's term for the bare
|
|
* `type/subtype` pair (https://mimesniff.spec.whatwg.org/#mime-type-essence);
|
|
* the Fetch standard's request classification is defined against it
|
|
* (https://fetch.spec.whatwg.org/#cors-safelisted-request-header).
|
|
*
|
|
* Parsing is RFC 9110 (`content-type` package) first. When the parameter
|
|
* section is malformed (`application/json;`, `application/json; charset=`),
|
|
* browsers and most HTTP stacks still derive the media type from the segment
|
|
* before the first `;` — the fallback matches that widely-implemented
|
|
* behavior, so a header whose media type is unambiguous is not rejected for
|
|
* a sloppy parameter section.
|
|
*/
|
|
export declare function mediaTypeEssence(header: string | null | undefined): string | undefined;
|
|
/**
|
|
* Whether a raw `Content-Type` header value denotes `application/json`.
|
|
* Parameters (for example `charset=utf-8`) are allowed and ignored; malformed
|
|
* parameter sections do not reject a header whose media type is unambiguously
|
|
* `application/json` (see `mediaTypeEssence` for the exact grammar).
|
|
*/
|
|
export declare function isJsonContentType(header: string | null | undefined): boolean;
|
|
//# sourceMappingURL=mediaType.d.ts.map |