UNPKG

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