/**
 * mock-xmlhttprequest v8.4.1
 * (c) 2025 Bertrand Guay-Paquet
 * @license MIT
 */

import type MockXhr from './MockXhr.cts';
import type MockXhrRequest from './MockXhrRequest.cts';
export type UrlMatcher = ((url: string) => boolean) | string | RegExp;
export interface RequestHandlerResponse {
    status: number;
    statusText: string;
    headers: Record<string, string>;
    body: unknown;
}
type RequestHandlerCallback = (request: MockXhrRequest) => void;
type SingleRequestHandler = Partial<RequestHandlerResponse> | RequestHandlerCallback | 'error' | 'timeout';
export type RequestHandler = SingleRequestHandler | SingleRequestHandler[];
interface RequestLogEntryInternal {
    method: string;
    url: string;
    headers: Record<string, string>;
    body?: unknown;
}
interface RequestLogEntry extends RequestLogEntryInternal {
    body?: any;
}
/**
 * Mock server for responding to XMLHttpRequest mocks from the class MockXhr. Provides simple route
 * matching and request handlers to make test harness creation easier.
 */
export default class MockXhrServer {
    /**
     * When this is greater than 0, the server automatically generates request (upload) and response
     * (download) progress events. The progress events have increments of "progressRate" bytes.
     *
     * This only applies to request handlers of type "object".
     */
    progressRate: number;
    private _MockXhr;
    private _requests;
    private _routes;
    private _xhrFactory;
    private _savedContext?;
    private _savedContextHadXMLHttpRequest?;
    private _savedXMLHttpRequest?;
    private _defaultRoute?;
    /**
     * Constructor
     *
     * @param xhrMock XMLHttpRequest mock class
     * @param routes Routes
     */
    constructor(xhrMock: typeof MockXhr, routes?: Record<string, [UrlMatcher, RequestHandler]>);
    get MockXhr(): typeof MockXhr;
    /**
     * For backwards compatibility with versions < 4.1.0
     *
     * @deprecated Use the MockXhr property instead
     */
    get xhrMock(): typeof MockXhr;
    get xhrFactory(): () => MockXhr;
    /**
     * Install the server's XMLHttpRequest mock in the global context. You can specify a different
     * context with the optional `context` argument. Revert with remove().
     *
     * @param context Context object (e.g. global, window)
     * @returns this
     */
    install(context?: {
        XMLHttpRequest?: unknown;
    }): this;
    /**
     * Revert the changes made by install(). Call this after your tests.
     */
    remove(): void;
    /**
     * Disable the effects of the timeout attribute on the XMLHttpRequest mock used by the server.
     *
     * @returns this
     */
    disableTimeout(): this;
    /**
     * Enable the effects of the timeout attribute on the XMLHttpRequest mock used by the server.
     *
     * @returns this
     */
    enableTimeout(): this;
    /**
     * Add a GET request handler.
     *
     * @param urlMatcher Url matcher
     * @param handler Request handler
     * @returns this
     */
    get(urlMatcher: UrlMatcher, handler: RequestHandler): this;
    /**
     * Add a POST request handler.
     *
     * @param urlMatcher Url matcher
     * @param handler Request handler
     * @returns this
     */
    post(urlMatcher: UrlMatcher, handler: RequestHandler): this;
    /**
     * Add a PUT request handler.
     *
     * @param urlMatcher Url matcher
     * @param handler Request handler
     * @returns this
     */
    put(urlMatcher: UrlMatcher, handler: RequestHandler): this;
    /**
     * Add a DELETE request handler.
     *
     * @param urlMatcher Url matcher
     * @param handler Request handler
     * @returns this
     */
    delete(urlMatcher: UrlMatcher, handler: RequestHandler): this;
    /**
     * Add a request handler.
     *
     * @param method HTTP method
     * @param urlMatcher Url matcher
     * @param handler Request handler
     * @returns this
     */
    addHandler(method: string, urlMatcher: UrlMatcher, handler: RequestHandler): this;
    /**
     * Set the default request handler for requests that don't match any route.
     *
     * @param handler Request handler
     * @returns this
     */
    setDefaultHandler(handler: RequestHandler): this;
    /**
     * Return 404 responses for requests that don't match any route.
     *
     * @returns this
     */
    setDefault404(): this;
    /**
     * @returns Array of requests received by the server. Entries: { method, url, headers, body? }
     */
    getRequestLog(): readonly RequestLogEntry[];
    private _handleRequest;
    private _findFirstMatchingRoute;
}
export {};
