import type { IncomingMessage as NodeIncomingMessage, ServerResponse as NodeServerResponse } from 'node:http';
import type { Socket } from 'node:net';
import { TLSSocket } from 'node:tls';
import { PassThrough } from 'node:stream';
import { Headers as ResponseHeaders } from './Headers.ts';
export declare const isBun: boolean;
interface IncomingMessage extends NodeIncomingMessage {
    authority?: string;
    socket: (Socket | TLSSocket) & {
        authorized?: boolean;
        encrypted?: boolean;
        getPeerCertificate?: (detailed?: boolean) => any;
        server?: {
            mtlsConfig?: any;
        };
    };
}
/**
 * We define our own request class, to ensure that it has integrity against leaks in a secure environment
 * and for better conformance to WHATWG standards.
 */
export declare class Request {
    #private;
    _nodeRequest: IncomingMessage;
    _nodeResponse?: NodeServerResponse;
    method: string;
    url: string;
    headers: RequestHeaders;
    requestId?: number;
    isOperationsServer?: boolean;
    handlerPath?: string;
    __harperdbRequestUpgraded?: boolean;
    __harperRequestUpgraded?: boolean;
    createdResource?: boolean;
    newLocation?: string;
    isWebSocket?: boolean;
    user?: any;
    response: {
        status?: number;
        headers: ResponseHeaders;
    };
    responseHeaders?: any;
    expiresAt?: number;
    onlyIfCached?: boolean;
    noCache?: boolean;
    noCacheStore?: boolean;
    staleIfError?: boolean;
    mustRevalidate?: boolean;
    replicatedConfirmation?: number;
    replicateTo?: any;
    replicateFrom?: any;
    data?: any;
    authorize?: boolean;
    lastModified?: number;
    lastRefreshed?: number;
    constructor(nodeRequest: IncomingMessage, nodeResponse?: NodeServerResponse);
    get signal(): AbortSignal;
    /**
     * Abort this request's signal. Used by transports (e.g. WebSocket) that need to
     * signal client-side cancellation independently of the Node response lifecycle.
     */
    _abort(): void;
    get absoluteURL(): string;
    get pathname(): string;
    set pathname(pathname: string);
    get protocol(): "http" | "https";
    get ip(): string;
    get authorized(): boolean;
    get peerCertificate(): any;
    get mtlsConfig(): any;
    get body(): RequestBody;
    get host(): string;
    get hostname(): string;
    get httpVersion(): string;
    get isAborted(): boolean;
    get nodeRequest(): IncomingMessage;
    /**
     * Invokes `handler` with a Node.js IncomingMessage/ServerResponse pair that adapts this Request
     * into the Node HTTP API, and returns a Promise that resolves to a Harper Response once the handler
     * writes its status and headers. Useful for integrating third-party Node middleware that expects
     * the native node http request/response objects.
     *
     * The IncomingMessage mirrors the current Request state (method, url, headers may have been modified
     * by middleware) while delegating body reading to the underlying stream. The ServerResponse captures
     * status, headers, and body, resolving the returned promise as soon as headers are available with a
     * streaming body that can be piped back through the Harper middleware chain.
     *
     * **Important:** The resolved `body` PassThrough must have an `error` listener attached (or be piped
     * to a destination that handles errors) before it is consumed. If the underlying connection is reset
     * after headers are sent, the body stream is destroyed with an error — without a listener, Node.js
     * will throw an uncaught exception.
     *
     * Example:
     *   server.http((request, next) =>
     *     request.withNodeAdapter((req, res) => someNodeMiddleware(req, res))
     *   );
     */
    withNodeAdapter(handler: (request: NodeIncomingMessage, response: NodeServerResponse) => void | Promise<void>): Promise<{
        status: number;
        headers: ResponseHeaders;
        body: PassThrough;
    }>;
    sendEarlyHints(link: string, headers?: Record<string, any>): void;
}
/**
 * Bun-compatible Request adapter. Wraps a Web Fetch API Request (from Bun.serve's fetch handler)
 * to present the same interface as the Node.js-based Request class.
 */
export declare class BunRequest {
    #private;
    _webRequest: globalThis.Request;
    _bunServer: any;
    _nodeRequest: any;
    _nodeResponse: any;
    method: string;
    url: string;
    headers: RequestHeaders;
    isWebSocket?: boolean;
    user?: any;
    response: {
        status?: number;
        headers: ResponseHeaders;
    };
    __harperRequestUpgraded: boolean;
    constructor(webRequest: globalThis.Request, bunServer: any, isSecure: boolean);
    get absoluteURL(): string;
    get pathname(): string;
    set pathname(pathname: string);
    get protocol(): "http" | "https";
    get ip(): string;
    get authorized(): any;
    get peerCertificate(): any;
    get mtlsConfig(): any;
    get body(): BunRequestBody;
    get host(): string;
    get hostname(): string;
    get httpVersion(): string;
    get isAborted(): boolean;
    get signal(): AbortSignal;
    _abort(): void;
    get nodeRequest(): any;
    sendEarlyHints(_link: string, _headers?: Record<string, any>): void;
}
declare class RequestBody {
    #private;
    constructor(nodeRequest: IncomingMessage);
    on(event: string, listener: (...args: any[]) => void): this;
    pipe(destination: any, options?: any): any;
}
declare class BunRequestBody {
    #private;
    constructor(webRequest: any);
    on(event: string, listener: (...args: any[]) => void): this;
    pipe(destination: any, options?: any): any;
}
declare class RequestHeaders {
    asObject: Record<string, string | string[]>;
    constructor(asObject: Record<string, string | string[]>);
    set(name: string, value: string | string[]): void;
    get(name: string): string | string[] | undefined;
    has(name: string): boolean;
    [Symbol.iterator](): ArrayIterator<[string, string | string[]]>;
    keys(): string[];
    values(): (string | string[])[];
    delete(name: string): void;
    forEach(callback: (value: string | string[], key: string, headers: RequestHeaders) => void): void;
}
export {};
