Fake Mirrors
    Preparing search index...

    Interface HttpServerContext

    Represents the http-server context of a normal HTTP request or WebSocket connection.

    Contains all request/response data, utility methods, and lifecycle state. This is the primary object passed to middleware functions.

    interface HttpServerContext {
        clientIp: string | null;
        connection: HttpConnection;
        finishTime: number;
        isBot: boolean;
        isComplete: boolean;
        method: HttpMethodWrap;
        requestBody: HttpBodyWrap;
        requestHeaders: HttpHeadersWrap;
        requestStream: Readable;
        responseBody: HttpBodyWrap;
        responseHeaders: HttpHeadersWrap;
        responseStream: Writable;
        startTime: number;
        state: object;
        status: HttpStatusWrap;
        totalTime: number;
        trace: string[];
        type: HttpServerContextType;
        url: HttpUrlWrap;
        userAgent: ParsedResult | null;
        close(): void;
        dump(): object;
        getState<T extends object, K extends string | number | symbol>(
            key: K,
        ): NonNullable<T[K]>;
        isRoute(
            method:
                | "HEAD"
                | "GET"
                | "POST"
                | "PUT"
                | "PATCH"
                | "DELETE"
                | "OPTIONS"
                | ("HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS")[],
            path: string | RegExp | (string | RegExp)[],
        ): boolean;
        loadRequest(bodySizeLimit: number): Promise<void>;
        sendHead(): void;
        sendResponse(): Promise<void>;
        setState<T extends object, K extends string | number | symbol>(
            key: K,
            value: T[K],
        ): void;
        sureNormal(): void;
        sureWebsocket(): void;
    }
    clientIp: string | null

    Parsed client IP address.

    connection: HttpConnection

    Parsed connection details.

    finishTime: number

    Timestamp when processing finished.

    isBot: boolean

    Whether the client is identified as a bot.

    isComplete: boolean

    Whether processing has completed.

    Request method wrapper.

    requestBody: HttpBodyWrap

    Request body wrapper.

    requestHeaders: HttpHeadersWrap

    Request headers wrapper.

    requestStream: Readable

    Readable stream for the request body.

    responseBody: HttpBodyWrap

    Response body wrapper.

    responseHeaders: HttpHeadersWrap

    Response headers wrapper.

    responseStream: Writable

    Writable stream for the response body.

    startTime: number

    Timestamp when processing started.

    state: object

    Associated shared state.

    Response status wrapper.

    totalTime: number

    Total processing time.

    trace: string[]

    Names of middleware that have already been processed.

    Associated context type.

    Request URL wrapper.

    userAgent: ParsedResult | null

    Parsed User-Agent data.

    • Closes the client connection.

      Returns void

    • Dumps a serializable representation of a context for logging.

      Returns object

      A plain object with context details.

    • Gets value by key from state.

      Type Parameters

      • T extends object
      • K extends string | number | symbol

      Parameters

      • key: K

      Returns NonNullable<T[K]>

    • Checks HTTP method and URL pathname.

      Parameters

      • method:
            | "HEAD"
            | "GET"
            | "POST"
            | "PUT"
            | "PATCH"
            | "DELETE"
            | "OPTIONS"
            | ("HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS")[]

        The single method string or an array of methods to check.

      • path: string | RegExp | (string | RegExp)[]

        The string path, RegExp pattern to match or array of both.

      Returns boolean

      true if the current method and pathname matches, false otherwise.

    • Loads the request body into memory.

      Parameters

      • bodySizeLimit: number

        The maximum body size in bytes.

      Returns Promise<void>

      HttpServerError If the body exceeds the size limit.

    • Sends the response headers to the client.

      Returns void

    • Sends the complete response to the client.

      Returns Promise<void>

    • Sets value by key to state.

      Type Parameters

      • T extends object
      • K extends string | number | symbol

      Parameters

      • key: K
      • value: T[K]

      Returns void

    • Checks if context type is 'normal'.

      Returns void

      Error If context type is not 'normal'.

    • Checks if context type is 'websocket'.

      Returns void

      Error If context type is not 'websocket'.