import net from 'net';
import tls from 'tls';
import http from 'http';
import { HttpEngine, HttpEngineOptions } from './HttpEngine.js';
import { IRequestLog } from '../../models/RequestLog.js';
import { IHttpRequest } from '../../models/HttpRequest.js';
import { Headers } from '../../lib/headers/Headers.js';
import { INtlmAuthorization } from '../../models/Authorization.js';
import { ResponseRedirect } from '../../models/ResponseRedirect.js';
export declare enum RequestState {
    Status = 0,
    Headers = 1,
    Body = 2,
    Done = 3
}
interface ResponseInfo {
    contentLength?: number;
    chunked: boolean;
    body?: Buffer;
    chunk?: Buffer;
    chunkSize?: number;
}
/**
 * API Client's HTTP engine.
 * 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 HttpEngine {
    state: RequestState;
    rawHeaders?: Buffer;
    _hostTestReg: RegExp;
    responseInfo: ResponseInfo;
    hasProxy: boolean;
    isProxyTunnel: boolean;
    isProxySsl: boolean;
    constructor(request: IHttpRequest, opts?: HttpEngineOptions);
    /**
     * Sends the request
     */
    send(): Promise<IRequestLog>;
    private sendRequest;
    /**
     * Cleans the state after finished.
     */
    _cleanUp(): void;
    /**
     * Cleans up the state for redirect.
     */
    _cleanUpRedirect(): void;
    /**
     * Prepares an HTTP message from API Client's request object.
     *
     * @returns Resolved promise to an `ArrayBuffer`.
     */
    prepareMessage(): Promise<Buffer>;
    /**
     * Sends a data to a socket.
     *
     * @param buffer HTTP message to send
     */
    writeMessage(buffer: Buffer): Promise<void>;
    /**
     * Connects to a server and sends the message.
     *
     * @returns Promise resolved when socket is connected.
     */
    connect(): Promise<net.Socket>;
    /**
     * Connects to a server and writes a message using insecure connection.
     *
     * @param port A port number to connect to.
     * @param host A host name to connect to
     * @returns A promise resolved when the message was sent to a server
     */
    _connect(port: number, host: string): Promise<net.Socket>;
    /**
     * Connects to a server and writes a message using secured connection.
     *
     * @param port A port number to connect to.
     * @param host A host name to connect to
     * @returns A promise resolved when the message was sent to a server
     */
    _connectTls(port: number, host: string): Promise<tls.TLSSocket>;
    /**
     * Prepares a full HTTP message body
     *
     * @param httpHeaders The list ogf headers to append.
     * @param buffer The buffer with the HTTP message
     * @returns The Buffer of the HTTP message
     */
    _prepareMessage(httpHeaders: Headers, buffer?: Buffer): Buffer;
    /**
     * Creates an HTTP status line for the message.
     * For proxy connections it, depending whether target is SSL or not, sets the path
     * as the full URL or just the authority.
     * @returns The generates status message.
     */
    _createHttpStatus(): string;
    /**
     * Tests if current connection is required to add `host` header.
     * It returns `false` only if `host` header has been already provided.
     *
     * @returns True when the `host` header should be added to the headers list.
     */
    _hostRequired(): boolean;
    /**
     * Alters authorization header depending on the `auth` object
     * @param headers A headers object where to append headers when needed
     */
    _handleAuthorization(headers: Headers): void;
    /**
     * Authorize the request with NTLM
     * @param authData Credentials to use
     * @param headers A headers object where to append headers if needed
     */
    _authorizeNtlm(authData: INtlmAuthorization, headers: Headers): void;
    /**
     * Add event listeners to existing socket.
     * @param socket An instance of the socket.
     * @return The same socket. Used for chaining.
     */
    _addSocketListeners(socket: net.Socket): net.Socket;
    /**
     * Processes response message chunk
     * @param buffer Message buffer
     */
    _processResponse(buffer: Buffer): void;
    /**
     * Reports response after processing it.
     */
    _reportResponse(): void;
    /**
     * Generate response object and publish it to the listeners.
     */
    _publishResponse(): Promise<void>;
    /**
     * @param location The redirect location.
     * @return Redirect response object
     */
    _createRedirectResponse(location: string): Promise<ResponseRedirect>;
    /**
     * closes the connection, if any
     */
    closeClient(): void;
    /**
     * Handles the response with NTLM authorization
     */
    handleNtlmResponse(): void;
    /**
     * Process received message.
     *
     * @param data Received message.
     */
    _processSocketMessage(data: Buffer): void;
    /**
     * Read status line from the response.
     * This function will set `status` and `statusText` fields
     * and then will set `state` to HEADERS.
     *
     * @param data The received data
     */
    _processStatus(data?: Buffer): Buffer | undefined;
    /**
     * Read headers from the received data.
     *
     * @param data Received data
     * @returns Remaining data in the buffer.
     */
    _processHeaders(data?: Buffer): Buffer | undefined;
    /**
     * Check the response headers and end the request if necessary.
     * @param data Current response data buffer
     */
    _postHeaders(data: Buffer): Buffer | undefined;
    /**
     * This function assumes that all headers has been read and it's
     * just before changing the status to BODY.
     */
    _parseHeaders(buffer?: Buffer): void;
    /**
     * @param data A data to process
     */
    _processBody(data?: Buffer): void;
    _processBodyContentLength(data: Buffer): void;
    /**
     * @param data A latest data to process
     */
    _processBodyChunked(data?: Buffer): void;
    /**
     * If response's Transfer-Encoding is 'chunked' read until next CR.
     * Everything before it is a chunk size.
     */
    readChunkSize(array: Buffer): Buffer | undefined;
    /**
     * Connects to a server through a proxy. Depending on the proxy type the returned socket
     * is a socket created after creating a tunnel (SSL) or the proxy socket.
     *
     * @returns Promise resolved when socket is connected.
     */
    connectProxy(): Promise<net.Socket | undefined>;
    /**
     * Creates a tunnel to a Proxy for SSL connections.
     * The returned socket is the one created after the tunnel is established.
     * @param proxyIsSsl Whether the proxy is an SSL connection.
     * @returns Promise resolved when socket is connected.
     */
    connectTunnel(proxyIsSsl?: boolean): Promise<net.Socket | undefined>;
    handleProxyAuthentication(res: http.IncomingMessage, socket: net.Socket): Promise<void>;
    /**
     * Creates connection to a proxy for an HTTP (non-SSL) transport.
     * This is the same as calling _connect or _connectTls but the target is the proxy and not the
     * target URL. The message sent to the proxy server is different than the one sent
     * to the target.
     * @param proxyIsSsl
     * @returns Promise resolved when socket is connected.
     */
    proxyHttp(proxyIsSsl?: boolean): Promise<net.Socket>;
}
export {};
//# sourceMappingURL=CoreEngine.d.ts.map