UNPKG

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