kinetex - v1.0.0-rc.1
    Preparing search index...

    Class RichHeaders

    RichHeaders extends HttpHeaders with typed getter/setter shortcuts for all commonly-used headers.

    Provides parsed accessors for:

    • Content-Type, Content-Disposition, Content-Range
    • Cache-Control, ETag, Last-Modified, Expires, Vary, Age
    • Authorization, WWW-Authenticate
    • Accept, Accept-Encoding, Accept-Language
    • Set-Cookie (via setCookies getter)
    • Link, Server-Timing, Alt-Svc
    • Forwarded / X-Forwarded-* normalization
    • CORS headers
    • Security headers (CSP, HSTS, etc.)
    const headers = new RichHeaders();
    headers.contentType = "application/json";
    headers.set("Content-Type", "text/html");
    console.log(headers.contentType?.charset); // "utf-8"

    headers.setCookies; // string[] of all Set-Cookie values

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • Optionalinit: HeadersInit | Record<string, string | string[]> | HttpHeaders | null

        Optional initial headers (WHATWG Headers, HttpHeaders, plain object, or [name, value][] array)

      • guard: HeadersGuard = "none"

        Guard mode (default: "none")

      Returns RichHeaders

    Accessors

    • get "[toStringTag]"(): string

      Returns string

      The string tag "HttpHeaders"

    • get size(): number

      Number of distinct header names.

      Returns number

    • get contentType(): ContentTypeValue | null

      Get the parsed Content-Type header value.

      Returns ContentTypeValue | null

    • set contentType(v: string | ContentTypeValue | null): void

      Set the Content-Type header from a string or parsed value.

      Parameters

      • v: string | ContentTypeValue | null

      Returns void

    • get contentLength(): number | null

      Get the Content-Length header value as a number.

      Returns number | null

    • set contentLength(v: number | null): void

      Set the Content-Length header from a number.

      Parameters

      • v: number | null

      Returns void

    • get contentDisposition(): ContentDispositionValue | null

      Get the parsed Content-Disposition header value.

      Returns ContentDispositionValue | null

    • set contentDisposition(v: string | ContentDispositionValue | null): void

      Set the Content-Disposition header from a string or parsed value.

      Parameters

      • v: string | ContentDispositionValue | null

      Returns void

    • get cacheControl(): CacheControlDirectives | null

      Get the parsed Cache-Control header directives.

      Returns CacheControlDirectives | null

    • set cacheControl(v: string | Partial<CacheControlDirectives> | null): void

      Set the Cache-Control header from a string or partial directives.

      Parameters

      • v: string | Partial<CacheControlDirectives> | null

      Returns void

    • get authorization(): AuthCredentials | null

      Get the parsed Authorization header credentials.

      Returns AuthCredentials | null

    • set authorization(v: string | null): void

      Set the Authorization header from a raw string.

      Parameters

      • v: string | null

      Returns void

    • get accept(): QualityValue[]

      Parsed Accept quality values sorted by q-factor

      Returns QualityValue[]

    • get acceptEncoding(): QualityValue[]

      Parsed Accept-Encoding quality values sorted by q-factor

      Returns QualityValue[]

    • get acceptLanguage(): QualityValue[]

      Parsed Accept-Language quality values sorted by q-factor

      Returns QualityValue[]

    • get range(): RangeSpec | null

      Parsed Range request header (RFC 7233)

      Returns RangeSpec | null

    • get contentRange(): ContentRangeValue | null

      Parsed Content-Range response header (RFC 7233)

      Returns ContentRangeValue | null

    • get etag(): string | null

      Get the ETag header value.

      Returns string | null

    • set etag(v: string | null): void

      Set the ETag header, automatically quoting if needed.

      Parameters

      • v: string | null

      Returns void

    • Get parsed Link header entries.

      Returns LinkValue[]

    • get retryAfter(): RetryAfterValue | null

      Get the parsed Retry-After header value.

      Returns RetryAfterValue | null

    • get hsts(): HSTSValue | null

      Get the parsed Strict-Transport-Security header value.

      Returns HSTSValue | null

    • set hsts(v: HSTSValue | null): void

      Set the Strict-Transport-Security header from an HSTS value.

      Parameters

      • v: HSTSValue | null

      Returns void

    • get csp(): CSPDirectiveMap | null

      Get the parsed Content-Security-Policy directives.

      Returns CSPDirectiveMap | null

    • set csp(v: string | CSPDirectiveMap | null): void

      Set the Content-Security-Policy header from a string or directive map.

      Parameters

      • v: string | CSPDirectiveMap | null

      Returns void

    • get serverTiming(): ServerTimingEntry[]

      Get parsed Server-Timing entries.

      Returns ServerTimingEntry[]

    • get clientIP(): string | null

      Best guess at real client IP from Forwarded / X-Forwarded-For / X-Real-IP

      Returns string | null

    • get forwarded(): ForwardedValue

      Normalized Forwarded or X-Forwarded-* information

      Returns ForwardedValue

    • get host(): string | null

      Raw Host header value

      Returns string | null

    • get origin(): string | null

      Raw Origin header value

      Returns string | null

    • get userAgent(): string | null

      Raw User-Agent header value

      Returns string | null

    • get location(): string | null

      Raw Location header value

      Returns string | null

    • get date(): Date | null

      Parsed Date header as a Date object

      Returns Date | null

    • get age(): number | null

      Parsed Age header in seconds

      Returns number | null

    • get vary(): string[]

      Parsed Vary header as an array of field names (lowercased)

      Returns string[]

    • get xRequestID(): string | null

      X-Request-ID header value

      Returns string | null

    • get xCorrelationID(): string | null

      X-Correlation-ID header value

      Returns string | null

    • get xPoweredBy(): string | null

      X-Powered-By header value

      Returns string | null

    • get xRequestedWith(): string | null

      X-Requested-With header value

      Returns string | null

    • get xRateLimitLimit(): number | null

      X-RateLimit-Limit header value (parsed as number)

      Returns number | null

    • get xRateLimitRemaining(): number | null

      X-RateLimit-Remaining header value (parsed as number)

      Returns number | null

    • get xRateLimitReset(): number | null

      X-RateLimit-Reset header value (parsed as number)

      Returns number | null

    • get secFetchSite(): string | null

      Sec-Fetch-Site header value

      Returns string | null

    • get secFetchMode(): string | null

      Sec-Fetch-Mode header value

      Returns string | null

    • get secFetchUser(): string | null

      Sec-Fetch-User header value

      Returns string | null

    • get secFetchDest(): string | null

      Sec-Fetch-Dest header value

      Returns string | null

    • get earlyData(): number | null

      Early-Data header value (parsed as number)

      Returns number | null

    • get priority(): string | null

      Priority header value

      Returns string | null

    • get allow(): string | null

      Allow header value

      Returns string | null

    • get server(): string | null

      Server header value

      Returns string | null

    • get acceptRanges(): string | null

      Accept-Ranges header value

      Returns string | null

    • get lastModified(): Date | null

      Parsed Last-Modified header as a Date object

      Returns Date | null

    • get expires(): Date | null

      Parsed Expires header as a Date object

      Returns Date | null

    • get contentEncoding(): string | null

      Content-Encoding header value

      Returns string | null

    • get contentLanguage(): string | null

      Content-Language header value

      Returns string | null

    • get contentLocation(): string | null

      Content-Location header value

      Returns string | null

    • First Link header entry (parsed)

      Returns LinkValue | null

    • get altSvc(): AltSvcEntry[]

      Parsed Alt-Svc entries

      Returns AltSvcEntry[]

    • get wwwAuthenticate(): AuthChallenge[] | null

      Get parsed WWW-Authenticate challenge entries.

      Returns AuthChallenge[] | null

    • set wwwAuthenticate(v: AuthChallenge[] | null): void

      Set the WWW-Authenticate header from challenge entries.

      Parameters

      • v: AuthChallenge[] | null

      Returns void

    • get proxyAuthenticate(): AuthChallenge[] | null

      Get parsed Proxy-Authenticate challenge entries.

      Returns AuthChallenge[] | null

    • set proxyAuthenticate(v: AuthChallenge[] | null): void

      Set the Proxy-Authenticate header from challenge entries.

      Parameters

      • v: AuthChallenge[] | null

      Returns void

    • get proxyAuthorization(): AuthCredentials | null

      Get the parsed Proxy-Authorization header credentials.

      Returns AuthCredentials | null

    • set proxyAuthorization(v: string | AuthCredentials | null): void

      Set the Proxy-Authorization header from a string or parsed credentials.

      Parameters

      • v: string | AuthCredentials | null

      Returns void

    • get setCookies(): string[]

      Get all Set-Cookie header values as an array.

      Returns string[]

    • get accessControlAllowOrigin(): string | null

      Access-Control-Allow-Origin header value

      Returns string | null

    • get accessControlAllowMethods(): string | null

      Access-Control-Allow-Methods header value

      Returns string | null

    • get accessControlAllowHeaders(): string | null

      Access-Control-Allow-Headers header value

      Returns string | null

    • get accessControlMaxAge(): number | null

      Access-Control-Max-Age header value (parsed as number)

      Returns number | null

    • get accessControlCredentials(): boolean | null

      Access-Control-Allow-Credentials header value (parsed as boolean)

      Returns boolean | null

    Methods

    • Append a value to an existing header (or create it). Unlike set, this does NOT overwrite existing values.

      Parameters

      • name: string

        Header name (case-insensitive)

      • value: string

        Header value (leading/trailing OWS stripped)

      Returns void

      TypeError If the guard forbids mutation or name/value is invalid

    • Delete a header by name.

      Parameters

      • name: string

        Header name (case-insensitive)

      Returns void

      TypeError If the guard forbids deletion

    • Return the combined value of a header. Multiple values are joined with ", " except for Set-Cookie / WWW-Authenticate / Proxy-Authenticate, which return only the first value.

      Parameters

      • name: string

        Header name (case-insensitive)

      Returns string | null

      The combined header value, or null if absent

    • Return all values for a header as an array (useful for Set-Cookie).

      Parameters

      • name: string

        Header name (case-insensitive)

      Returns string[]

      Array of values (empty if absent)

    • Check if a header exists.

      Parameters

      • name: string

        Header name (case-insensitive)

      Returns boolean

      true if the header is set

    • Set a header, overwriting any existing values for that name.

      Parameters

      • name: string

        Header name (case-insensitive)

      • value: string

        Header value (leading/trailing OWS stripped)

      Returns void

      TypeError If the guard forbids mutation or name/value is invalid

    • Execute a callback for each header entry. Multi-value headers are joined with ", " for the callback, except for Set-Cookie (each value is called separately).

      Parameters

      • callback: (value: string, name: string, headers: HttpHeaders) => void

        Called once per combined value with (value, name, headers)

      • OptionalthisArg: unknown

        Value for this inside the callback

      Returns void

    • Iterator over all header names (lowercased).

      Returns IterableIterator<string>

    • Iterator over all header values. Multi-value headers are joined with ", " except Set-Cookie.

      Returns IterableIterator<string>

    • Iterator over [name, value] tuples (WHATWG Headers-compatible).

      Returns IterableIterator<[string, string]>

    • Convert to a plain object. Multi-value headers become arrays.

      Returns Record<string, string | string[]>

    • Convert to WHATWG Headers (when available in the runtime).

      Returns Headers

      If WHATWG Headers is not available in this runtime

    • Merge another headers source into this one. Existing values are overwritten unless append is true.

      Parameters

      • other: Record<string, string | string[]> | HttpHeaders
      • options: { append?: boolean } = {}

      Returns this