59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
/// <reference types="node" />
|
|
/// <reference types="node" />
|
|
/// <reference types="node" />
|
|
import { AxiosRequestConfig } from 'axios';
|
|
import { URLSearchParams } from 'url';
|
|
import { IncomingMessage } from 'http';
|
|
import { ProxyConfig } from './types';
|
|
type HttpMethod = 'GET' | 'DELETE' | 'POST' | 'PUT' | 'PATCH';
|
|
/**
|
|
* Options for sending HTTP requests.
|
|
* @private
|
|
*/
|
|
interface SendRequestOptions {
|
|
/**
|
|
* Fields to include in message body (or params). Values must be either strings, or arrays of
|
|
* strings (for repeated parameters).
|
|
*/
|
|
data?: URLSearchParams;
|
|
/** Extra HTTP headers to include in request, in addition to headers defined in constructor. */
|
|
headers?: Record<string, string>;
|
|
/** Buffer containing file data to include. */
|
|
fileBuffer?: Buffer;
|
|
/** Filename of file to include. */
|
|
filename?: string;
|
|
}
|
|
/**
|
|
* Internal class implementing HTTP requests.
|
|
* @private
|
|
*/
|
|
export declare class HttpClient {
|
|
private readonly serverUrl;
|
|
private readonly headers;
|
|
private readonly minTimeout;
|
|
private readonly maxRetries;
|
|
private readonly proxy?;
|
|
constructor(serverUrl: string, headers: Record<string, string>, maxRetries: number, minTimeout: number, proxy?: ProxyConfig);
|
|
prepareRequest(method: HttpMethod, url: string, timeoutMs: number, responseAsStream: boolean, options: SendRequestOptions): AxiosRequestConfig;
|
|
/**
|
|
* Makes API request retrying if necessary, and returns (as Promise) response.
|
|
* @param method HTTP method, for example 'GET'
|
|
* @param url Path to endpoint, excluding base server URL.
|
|
* @param options Additional options controlling request.
|
|
* @param responseAsStream Set to true if the return type is IncomingMessage.
|
|
* @return Fulfills with status code and response (as text or stream).
|
|
*/
|
|
sendRequestWithBackoff<TContent extends string | IncomingMessage>(method: HttpMethod, url: string, options?: SendRequestOptions, responseAsStream?: boolean): Promise<{
|
|
statusCode: number;
|
|
content: TContent;
|
|
}>;
|
|
/**
|
|
* Performs given HTTP request and returns status code and response content (text or stream).
|
|
* @param axiosRequestConfig
|
|
* @private
|
|
*/
|
|
private static sendAxiosRequest;
|
|
private static shouldRetry;
|
|
}
|
|
export {};
|