Headers
Models HTTP headers for the unstable HTTP client and server modules.
Headers values are immutable maps keyed by lowercase header name. This module converts common header inputs into that shape, provides helpers for reading and updating header values, and redacts configured sensitive headers when values are inspected.
Combinators
Signature
declare const get: {
(key: string): (self: Headers) => Option<string>;
(self: Headers, key: string): Option<string>;
};Returns true when a header with the given name is present.
Details
The lookup lowercases the provided header name.
Signature
declare const has: {
(key: string): (self: Headers) => boolean;
(self: Headers, key: string): boolean;
};Returns a new Headers collection containing headers from both collections.
Details
Headers from the second collection override headers from the first collection with the same name.
Signature
declare const merge: {
(headers: Headers): (self: Headers) => Headers;
(self: Headers, headers: Headers): Headers;
};Returns a plain record with selected header values wrapped in Redacted.
Details
String keys are normalized to lowercase before matching; regular expressions are tested against the stored header names.
Signature
declare const redact: {
(key: string | RegExp | readonly Array<string | RegExp>): (self: Headers) => Record<string, string | Redacted.Redacted>;
(self: Headers, key: string | RegExp | readonly Array<string | RegExp>): Record<string, string | Redacted.Redacted>;
}Returns a new Headers collection with the named header removed.
Details
The provided header name is normalized to lowercase before removal.
Signature
declare const remove: {
(key: string): (self: Headers) => Headers;
(self: Headers, key: string): Headers;
};removeMany
Returns a new Headers collection with each named header removed.
Details
Each provided header name is normalized to lowercase before removal.
Signature
declare const removeMany: {
(keys: Iterable<string>): (self: Headers) => Headers;
(self: Headers, keys: Iterable<string>): Headers;
};Returns a new Headers collection with the given header set.
Details
The header name is normalized to lowercase.
Signature
declare const set: {
(key: string, value: string): (self: Headers) => Headers;
(self: Headers, key: string, value: string): Headers;
};Returns a new Headers collection with all provided headers set.
Details
Input headers are normalized with fromInput and override existing headers with the same lowercase name.
Signature
declare const setAll: {
(headers: Input): (self: Headers) => Headers;
(self: Headers, headers: Input): Headers;
};Constructors
An empty Headers collection.
Signature
declare const empty: Headers;Creates Headers from a record or iterable of header entries.
Details
Header names are normalized to lowercase. Array values in record input are joined with ", ", and undefined values are omitted.
Signature
declare const fromInput: (input?: Input) => Headers;fromRecordUnsafe
Treats an existing record as Headers unsafely.
Gotchas
This mutates the record's prototype and does not normalize header names; callers must provide the expected lowercase keys.
Signature
declare function fromRecordUnsafe(input: Record.ReadonlyRecord<string, string>): Headers;Guards
Instances
Equivalence
Provides an Equivalence instance that compares Headers by header names and string values.
Signature
declare const Equivalence: Equ.Equivalence<Headers>;Models
Represents an immutable HTTP header collection keyed by lowercase header name.
Details
Headers values also support redaction through the Redactable protocol.
Signature
interface Headers extends Redactable {
[key: string]: string;
readonly [TypeId]: typeof TypeId;
}Input accepted when constructing headers.
Details
Records may contain string values, string arrays, or undefined; arrays are joined with ", ", and undefined values are omitted.
Signature
type Input =
| Record.ReadonlyRecord<string, string | ReadonlyArray<string> | undefined>
| Iterable<readonly [string, string]>;Schemas
HeadersSchema
Schema for Headers values encoded as records of string header values.
Details
Decoding normalizes header names through fromInput; encoding returns a plain record.
Signature
declare const HeadersSchema: HeadersSchema;HeadersSchema interface
Schema interface for Headers values encoded as records of string header values.
Signature
interface HeadersSchema extends declare<
Headers,
{
[x: string]: string;
}
> {
constructor(_: never);
}Services
CurrentRedactedNames
Context reference listing header names or patterns that should be redacted when Headers are inspected or rendered.
Details
Defaults include authorization, cookie, set-cookie, and x-api-key.
Signature
declare const CurrentRedactedNames: Reference<readonly Array<string | RegExp>>
Gets a header value by name safely.
Details
The lookup lowercases the provided header name and returns
Option.none()when absent.