/**
 * Copyright (c) OpenLens Maintainers. All rights reserved.
 * Licensed under MIT License. See LICENSE in root directory for more information.
 */
/// <reference types="node" />
/// <reference types="node" />
import https from "https";
import type http from "http";
import type httpProxy from "http-proxy";
import type { Router } from "../router/router";
import type { Cluster } from "../../common/cluster/cluster";
import type { ProxyApiRequestArgs } from "./proxy-functions";
import type { SetRequired } from "type-fest";
import type { EmitAppEvent } from "../../common/app-event-bus/emit-event.injectable";
import type { Logger } from "@openlens/logger";
import type { SelfSignedCert } from "selfsigned";
import type { KubeAuthProxyServer } from "../cluster/kube-auth-proxy-server.injectable";
import stoppable from "stoppable";
export type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | undefined;
export type ServerIncomingMessage = SetRequired<http.IncomingMessage, "url" | "method">;
export type LensProxyApiRequest = (args: ProxyApiRequestArgs) => void | Promise<void>;
interface Dependencies {
    getClusterForRequest: GetClusterForRequest;
    shellApiRequest: LensProxyApiRequest;
    kubeApiUpgradeRequest: LensProxyApiRequest;
    emitAppEvent: EmitAppEvent;
    getKubeAuthProxyServer: (cluster: Cluster) => KubeAuthProxyServer;
    readonly router: Router;
    readonly proxy: httpProxy;
    readonly lensProxyPort: {
        set: (portNumber: number) => void;
    };
    readonly contentSecurityPolicy: string;
    readonly logger: Logger;
    readonly certificate: SelfSignedCert;
}
export declare function isLongRunningRequest(reqUrl: string): boolean;
export declare class LensProxy {
    private readonly dependencies;
    protected readonly proxyServer: https.Server & stoppable.WithStop;
    protected closed: boolean;
    protected readonly retryCounters: Map<string, number>;
    constructor(dependencies: Dependencies);
    /**
     * Starts to listen on an OS provided port. Will reject if the server throws
     * an error.
     *
     * Resolves with the port number that was picked
     */
    private attemptToListen;
    /**
     * Starts the lens proxy.
     * @resolves After the server is listening on a good port
     * @rejects if there is an error before that happens
     */
    listen(): Promise<void>;
    close(): Promise<void> | undefined;
    protected configureProxy(proxy: httpProxy): httpProxy;
    protected getRequestId(req: http.IncomingMessage): string;
    protected handleRequest(req: ServerIncomingMessage, res: http.ServerResponse): Promise<void>;
}
export {};
