http-header
v1.1.0
Published
Utilities for working with HTTP headers.
Downloads
6
Readme
http-header
Utilities for working with HTTP headers.
API
import {
deleteHeader,
getHeader,
getHeaderName,
hasHeader,
HeaderNotFoundError,
InvalidHeaderNameError,
InvalidHeaderValueError,
setHeader,
setHeaderName
} from 'http-header';
import type {
HeaderNameType,
HeadersType,
HeaderValueType
} from 'http-header';
deleteHeader(headers: HeadersType, name: HeaderNameType) => HeadersType;
getHeader(headers: HeadersType, name: HeaderNameType) => HeaderValueType;
getHeaderName(headers: HeadersType, name: HeaderNameType) => HeaderNameType;
hasHeader(headers: HeadersType, name: HeaderNameType) => boolean;
setHeader(headers: HeadersType, name: HeaderNameType, value: HeaderValueType) => HeadersType;
setHeaderName(headers: HeadersType, oldName: HeaderNameType, newName: HeaderNameType) => HeadersType;
Behaviour
HeaderNotFoundError
error
getHeader
and getHeaderName
throw HeaderNotFoundError
if the specified header cannot be found.
Use hasHeader
to check if the header exists before using getHeader
or getHeaderName
, e.g.
import {
hasHeader,
getHeader
} from 'http-header';
if (hasHeader('Content-Type')) {
getHeader('Content-Type');
}