Setu-TS
    Preparing search index...

    Interface IRequest

    Runtime-agnostic view of an incoming HTTP request.

    0.1.0

    interface IRequest {
        headers: Headers;
        ip?: string;
        locale?: string;
        method: HttpMethod;
        path: string;
        raw?: Request;
        signal?: AbortSignal;
        tenant?: ITenant;
        url: string;
        user?: IPrincipal;
        bytes(): Promise<Uint8Array<ArrayBufferLike>>;
        formData?(): Promise<FormBody>;
        json<T = unknown>(): Promise<T>;
        text(): Promise<string>;
    }
    Index
    headers: Headers

    Request headers (web-standard Headers).

    ip?: string

    Socket peer on Node, Deno and Bun; absent on Workers and plain fetch calls. Behind a proxy this is the proxy. Read CLIENT_IP_STATE_KEY for the resolved client.

    locale?: string

    The resolved locale — a BCP 47 tag from the application's supported set — populated by the localization plugin's middleware (priority 45). Absent when no localization plugin is registered, or on a path its middleware excludes.

    Like tenant, it accepts one implicit write per request; use replaceLocale for an intentional replacement, such as applying a signed-in user's saved preference once authentication (300) has run. Three things to keep in mind: a reader running at a LOWER middleware priority than 45 sees undefined (the priority table orders them, exactly as for tenant at 40); a response cache keys on the value present when the cache runs, so an override must precede the cache lookup to be reflected in it; and this is a preference, never an authorization input — any client can choose any supported locale.

    0.9.0

    method: HttpMethod

    The HTTP method.

    path: string

    The URL path component (no query string).

    raw?: Request

    The undisturbed web-standard Request, preserved for WebSocket upgrade and gRPC dispatch after the middleware pipeline.

    Populated by the HTTP adapter before the body is consumed by the framework mapping. Optional because injected or test requests may not carry one.

    0.3.0

    signal?: AbortSignal

    An abort signal that fires when the underlying HTTP connection is severed (client disconnect, timeout). Populated by the HTTP adapter from the native Request.signal; optional because injected / test requests may not carry one.

    When absent, the kernel's request-context factory falls back to a non-aborting sentinel so that producers reading IRequestContext.signal always have a live signal to listen on.

    tenant?: ITenant

    The resolved tenant, populated by the multi-tenancy middleware. Absent when no tenant could be resolved or multi-tenancy is not enabled.

    It accepts one implicit write per request; use replaceTenant for an intentional replacement. Like user, this detects late accidental overwrites and is not an authorization control.

    url: string

    The full request URL.

    user?: IPrincipal

    The authenticated principal, populated by authentication middleware. Absent when the request is unauthenticated.

    It accepts one implicit write per request; a second assignment throws so independent identity writers fail loudly. Use replacePrincipal for an intentional replacement such as step-up authentication. This is not an authorization control: a write before authentication is still the first write and is allowed.

    • Reads the body as raw bytes.

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The body bytes

    • Reads the body as a form, for both application/x-www-form-urlencoded and multipart/form-data requests.

      The parse is the shared parseFormBody, memoized exactly as json() is — the in-flight promise is cached (a rejection with it), so two middleware reading the same body trigger one parse, not two.

      Optional on the signal? / fs? / raw? precedent: a custom IRequest implementor may omit it. Such a caller falls back to parseFormBody(await request.bytes(), request.headers.get('content-type')), the same common function the producers call — what the accessor adds over the fallback is the memoization.

      Returns Promise<FormBody>

      The parsed form. A multipart body the parser cannot make sense of yields an EMPTY form rather than a rejection: the promoted parser's released behaviour, kept so the accessor changes where parsing happens, never what a parse yields.

      If the content-type is neither form encoding — a JSON body, a missing content-type, or a multipart type with no boundary=. Branded 415, so an application running errorHandler answers 415 Unsupported Media Type in its configured format rather than a masked 500.

      0.5.0

    • Reads and parses the body as JSON.

      Type Parameters

      • T = unknown

        The expected body shape (validate before trusting)

      Returns Promise<T>

      The parsed body

      If the body is not valid JSON. The error carries a 400 HTTP status hint, so an application running errorHandler answers the malformed body with 400 Bad Request in its configured format rather than a masked 500 (X37-1). A handler that catches the rejection keeps full control of what is served.