IMPORT_PATH: "@daiso-tech/core/http-router"

Implements

Constructors

Methods

  • Appends a value to an existing response header instead of overwriting it.

    Useful for headers that support multiple values (e.g. Vary, Link, Set-Cookie). Unlike setHeader, this adds the value alongside any existing ones rather than replacing them.

    Parameters

    • key: string

      The header name.

    • value: string

      The header value to append.

    Returns IHttpRes

  • Builds and returns the final Web API Response object from all configured headers, status, cookies, and body.

    You typically don't need to call this in handler functions — the HttpRouter class calls it automatically. Use it directly only in isolation, such as during testing.

    Returns Response

    The constructed HTTP response.

  • Returns the current value of a response header, or an empty string if not set.

    Parameters

    • key: string

      The header name.

    Returns null | string

    The header value, or null if absent.

  • Checks whether any Set-Cookie headers are present, or whether a header with the given name exists when one is provided.

    Parameters

    • Optionalname: string

      Optional. The name of the cookie to check. When omitted, returns true if at least one Set-Cookie header exists.

    Returns boolean

    true if a matching or any Set-Cookie header is present.

  • Adds a Set-Cookie header if one does not exist, or updates it if a header with the given name is already present.

    Parameters

    • name: string

      The name of the cookie.

    • value: string

      The cookie value.

    • settings: CookieSetSettings = {}

      Optional cookie attributes (expires, httpOnly, etc.).

    Returns IHttpRes

    This instance for chaining.

  • Adds or updates a Set-Cookie header with Max-Age=0 for the given name, expiring the cookie when the response is sent.

    If a Set-Cookie header with the given name already exists, it is replaced with an expired version. Otherwise an expired header is appended to ensure the client removes any matching cookie.

    Parameters

    • name: string

      The name of the cookie to expire.

    • Optionalsettings: CookieScope

      Optional scope attributes (path, secure, domain) to match the cookie that was originally set.

    Returns IHttpRes

    This instance for chaining.

  • Sets the response body as raw bytes without overriding the Content-Type header.

    Accepts a string, binary buffer, or an async iterable of byte chunks for streaming. Useful when the caller wants full control over the Content-Type header.

    Parameters

    • content:
          | string
          | ArrayBuffer
          | Uint8Array<ArrayBufferLike>
          | AsyncIterable<Uint8Array<ArrayBufferLike>, any, any>

      The response body content.

    Returns IHttpRes

  • Sets an arbitrary response header by key and value.

    Useful for headers that don't have a dedicated setter method, such as custom headers or less common standard headers.

    Parameters

    • key: string

      The header name (e.g. "X-Custom-Header").

    • value: string

      The header value.

    Returns IHttpRes

  • Strips all Set-Cookie headers from the response builder, or only the header matching the given name when one is provided.

    Parameters

    • Optionalname: string

      Optional. The name of the cookie to strip. When omitted, all Set-Cookie headers are removed.

    Returns IHttpRes

    This instance for chaining.