UNPKG

3.51 kBTypeScriptView Raw
1/// <reference types="node" />
2import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http";
3import { Transform } from "stream";
4import { URL } from "url";
5import { CancellationToken } from "./CancellationToken";
6import { ProgressInfo } from "./ProgressCallbackTransform";
7export interface RequestHeaders extends OutgoingHttpHeaders {
8 [key: string]: string;
9}
10export interface DownloadOptions {
11 readonly headers?: OutgoingHttpHeaders | null;
12 readonly sha2?: string | null;
13 readonly sha512?: string | null;
14 readonly cancellationToken: CancellationToken;
15 onProgress?(progress: ProgressInfo): void;
16}
17export declare function createHttpError(response: IncomingMessage, description?: any | null): HttpError;
18export declare class HttpError extends Error {
19 readonly statusCode: number;
20 readonly description: any | null;
21 constructor(statusCode: number, message?: string, description?: any | null);
22}
23export declare function parseJson(result: Promise<string | null>): Promise<any>;
24export declare abstract class HttpExecutor<REQUEST> {
25 protected readonly maxRedirects = 10;
26 request(options: RequestOptions, cancellationToken?: CancellationToken, data?: {
27 [name: string]: any;
28 } | null): Promise<string | null>;
29 doApiRequest(options: RequestOptions, cancellationToken: CancellationToken, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void, redirectCount?: number): Promise<string>;
30 protected addRedirectHandlers(request: any, options: RequestOptions, reject: (error: Error) => void, redirectCount: number, handler: (options: RequestOptions) => void): void;
31 addErrorAndTimeoutHandlers(request: any, reject: (error: Error) => void): void;
32 private handleResponse;
33 abstract createRequest(options: any, callback: (response: any) => void): any;
34 downloadToBuffer(url: URL, options: DownloadOptions): Promise<Buffer>;
35 protected doDownload(requestOptions: any, options: DownloadCallOptions, redirectCount: number): void;
36 protected createMaxRedirectError(): Error;
37 private addTimeOutHandler;
38 static prepareRedirectUrlOptions(redirectUrl: string, options: RequestOptions): RequestOptions;
39}
40export interface DownloadCallOptions {
41 responseHandler: ((response: IncomingMessage, callback: (error: Error | null) => void) => void) | null;
42 onCancel: (callback: () => void) => void;
43 callback: (error: Error | null) => void;
44 options: DownloadOptions;
45 destination: string | null;
46}
47export declare function configureRequestOptionsFromUrl(url: string, options: RequestOptions): RequestOptions;
48export declare function configureRequestUrl(url: URL, options: RequestOptions): void;
49export declare class DigestTransform extends Transform {
50 readonly expected: string;
51 private readonly algorithm;
52 private readonly encoding;
53 private readonly digester;
54 private _actual;
55 readonly actual: string | null;
56 isValidateOnEnd: boolean;
57 constructor(expected: string, algorithm?: string, encoding?: "hex" | "base64" | "latin1");
58 _transform(chunk: Buffer, encoding: string, callback: any): void;
59 _flush(callback: any): void;
60 validate(): null;
61}
62export declare function safeGetHeader(response: any, headerKey: string): any;
63export declare function configureRequestOptions(options: RequestOptions, token?: string | null, method?: "GET" | "DELETE" | "PUT"): RequestOptions;
64export declare function safeStringifyJson(data: any, skippedNames?: Set<string>): string;