import net from 'net';
import { URL } from 'url';
import tls from 'tls';
import { EventEmitter } from 'events';
import { Logger, type ILogObj } from 'tslog';
import { IRequestLog } from '../../models/RequestLog.js';
import { IHttpRequest, HttpRequest } from '../../models/HttpRequest.js';
import { IRequestBaseConfig } from '../../models/RequestConfig.js';
import { IRequestAuthorization } from '../../models/RequestAuthorization.js';
import { HttpCertificate } from '../../models/ClientCertificate.js';
import { SentRequest } from '../../models/SentRequest.js';
import { Response } from '../../models/Response.js';
import { ResponseRedirect } from '../../models/ResponseRedirect.js';
import { RequestLog } from '../../models/RequestLog.js';
import { RequestTime } from '../../models/RequestTime.js';
import { SerializableError } from '../../models/SerializableError.js';
import { ResponseAuthorization } from '../../models/ResponseAuthorization.js';
import { Headers } from '../../lib/headers/Headers.js';
export interface HttpEngineOptions extends IRequestBaseConfig {
    /**
     * The authorization configuration to apply to the request.
     */
    authorization?: IRequestAuthorization[];
    /**
     * Logger object.
     */
    logger?: Logger<ILogObj>;
    /**
     * A certificate to use with the request.
     */
    certificates?: HttpCertificate[];
}
export interface RequestStats {
    firstReceiveTime?: number;
    lastReceivedTime?: number;
    messageStart?: number;
    sentTime?: number;
    connectionTime?: number;
    lookupTime?: number;
    connectedTime?: number;
    secureStartTime?: number;
    secureConnectedTime?: number;
    startTime?: number;
    responseTime?: number;
    receivingTime?: number;
}
export interface ResponseErrorInit {
    code?: number | string;
    message?: string;
}
export interface BeforeRedirectDetail {
    location: string;
    returnValue: boolean;
}
export interface HeadersReceivedDetail {
    value: string;
    returnValue: boolean;
}
export interface IRequestAuthState {
    method: 'ntlm';
    state: number;
    headers?: string;
    challengeHeader?: string;
}
export declare const mainPromiseSymbol: unique symbol;
/**
 * API Client's HTTP engine with refactored parsing and connection handling.
 * An HTTP 1.1 engine working directly on the socket. It communicates with the remote machine and
 * collects stats about the request and response.
 */
export declare class CoreEngine extends EventEmitter {
    request: HttpRequest;
    opts: HttpEngineOptions;
    logger: Logger<ILogObj>;
    /**
     * The current sent request
     */
    sentRequest: SentRequest;
    redirects: ResponseRedirect[];
    /**
     * When true the request has been aborted.
     */
    aborted: boolean;
    /**
     * Parsed value of the request URL.
     */
    uri: URL;
    socket?: net.Socket;
    /**
     * Host header can be different than registered URL because of
     * `hosts` rules.
     * If a rule changes host value of the URL the original URL host value
     * is used when generating the request and not overwritten one.
     * This way virtual hosts can be tested using hosts.
     */
    hostHeader: string | undefined;
    protected hostTestReg: RegExp;
    /**
     * Set when the request is redirected.
     */
    redirecting: boolean;
    /**
     * The response headers.
     * The object may be empty when the response is not set.
     */
    currentHeaders: Headers;
    /**
     * The response object build during the execution.
     */
    currentResponse?: Response;
    /**
     * Keeps the raw body in a temporary buffer while processing the response.
     */
    _rawBody?: Buffer;
    stats: RequestStats;
    auth?: IRequestAuthState;
    protected mainResolver?: (log: IRequestLog) => void;
    protected mainRejecter?: (err: SerializableError) => void;
    [mainPromiseSymbol]?: Promise<IRequestLog>;
    protected _signal?: AbortSignal;
    private parser;
    private connectionManager;
    private authManager;
    private messageBuilder;
    hasProxy: boolean;
    isProxyTunnel: boolean;
    isProxySsl: boolean;
    /**
     * @return True if following redirects is allowed.
     */
    get followRedirects(): boolean;
    /**
     * The request timeout.
     */
    get timeout(): number;
    /**
     * The abort signal to set on this request.
     * Aborts the request when the signal fires.
     */
    get signal(): AbortSignal | undefined;
    set signal(value: AbortSignal | undefined);
    constructor(request: IHttpRequest, opts?: HttpEngineOptions);
    /**
     * Creates a logger object to log debug output.
     */
    setupLogger(opts?: HttpEngineOptions): Logger<ILogObj>;
    /**
     * Updates the `uri` property from current request URL
     */
    readUrl(value: string): URL;
    /**
     * Get host header for the request
     */
    getHostHeader(url: string): string | undefined;
    /**
     * Aborts current request.
     * It emits `error` event
     */
    abort(): void;
    /**
     * Handler for the `abort` event on the `AbortSignal`.
     */
    protected _abortHandler(): void;
    /**
     * Create parser callbacks to handle parsed data
     */
    private createParserCallbacks;
    /**
     * Sends the request
     */
    send(): Promise<IRequestLog>;
    private sendRequest;
    /**
     * Establish connection using the connection manager
     */
    private establishConnection;
    /**
     * Decompresses received body if `content-encoding` header is set.
     */
    decompress(body?: Buffer): Promise<Buffer | undefined>;
    /**
     * Prepares headers list to be send to the remote machine.
     * If `defaultHeaders` option is set then it adds `user-agent` and `accept`
     * headers.
     */
    prepareHeaders(headers: Headers, withPayload?: boolean): void;
    /**
     * Cleans the state after finished.
     */
    _cleanUp(): void;
    /**
     * Cleans up the state for redirect.
     */
    _cleanUpRedirect(): void;
    /**
     * Reports response when redirected.
     */
    _reportRedirect(status: number): boolean;
    /**
     * Get redirect options based on status and method
     */
    private getRedirectOptions;
    /**
     * Creates a response and adds it to the redirects list and redirects
     * the request to the new location.
     */
    _redirectRequest(options: {
        redirect: boolean;
        location?: string;
        forceGet?: boolean;
    }): Promise<void>;
    /**
     * Get redirect location
     */
    private getRedirectLocation;
    /**
     * Check if redirect is a loop
     */
    private isRedirectLoop;
    /**
     * @param location The redirect location.
     * @return Redirect response object
     */
    _createRedirectResponse(location: string): Promise<ResponseRedirect>;
    /**
     * Creates a response object
     */
    _createResponse(): Promise<Response>;
    /**
     * Finishes the response with error message.
     */
    _errorRequest(opts: ResponseErrorInit): void;
    /**
     * Generates authorization info object from response.
     */
    _getAuth(): ResponseAuthorization;
    /**
     * Creates HAR 1.2 timings object from stats.
     */
    _computeStats(stats: RequestStats): RequestTime;
    /**
     * Handles cookie exchange when redirecting the request.
     */
    _processRedirectCookies(responseCookies: string, location: string): void;
    /**
     * Checks certificate identity using TLS api.
     */
    _checkServerIdentity(host: string, cert: tls.PeerCertificate): Error | undefined;
    /**
     * Clears event listeners of the socket object,
     */
    _clearSocketEventListeners(): void;
    /**
     * Called with the `send()` function to initialize the main promise returned by the send function.
     * The send function returns a promise that is resolved when the request finish.
     */
    protected wrapExecution(): Promise<IRequestLog>;
    /**
     * Called by the request finalizer or error finalized to report the response.
     */
    protected finalizeRequest(log: RequestLog | SerializableError): void;
    /**
     * Prepares an HTTP message from API Client's request object.
     */
    prepareMessage(): Promise<Buffer>;
    /**
     * Sends a data to a socket.
     */
    writeMessage(buffer: Buffer): Promise<void>;
    /**
     * Alters authorization header depending on the `auth` object
     */
    _handleAuthorization(headers: Headers): void;
    /**
     * Generate proxy authorization header
     */
    _proxyAuthHeader(): string | undefined;
    /**
     * Add event listeners to existing socket.
     */
    _addSocketListeners(socket: net.Socket): net.Socket;
    /**
     * Reports response after processing it.
     */
    _reportResponse(): Promise<void>;
    /**
     * Generate response object and publish it to the listeners.
     */
    _publishResponse(): Promise<void>;
    /**
     * closes the connection, if any
     */
    closeClient(): void;
    /**
     * Handles the response with NTLM authorization
     */
    handleNtlmResponse(): Promise<void>;
}
//# sourceMappingURL=CoreEngine.d.ts.map