1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import { BinaryToTextEncoding } from "crypto";
|
7 | import { IncomingMessage, OutgoingHttpHeader, OutgoingHttpHeaders, RequestOptions } from "http";
|
8 | import { Transform } from "stream";
|
9 | import { URL } from "url";
|
10 | import { CancellationToken } from "./CancellationToken";
|
11 | import { ProgressInfo } from "./ProgressCallbackTransform";
|
12 | export interface RequestHeaders extends OutgoingHttpHeaders {
|
13 | [key: string]: OutgoingHttpHeader | undefined;
|
14 | }
|
15 | export 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 | }
|
22 | export declare function createHttpError(response: IncomingMessage, description?: any | null): HttpError;
|
23 | export 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 | }
|
29 | export declare function parseJson(result: Promise<string | null>): Promise<any>;
|
30 | interface Request {
|
31 | abort: () => void;
|
32 | end: (data?: Buffer) => void;
|
33 | }
|
34 | export 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 | }
|
51 | export 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 | }
|
58 | export declare function configureRequestOptionsFromUrl(url: string, options: RequestOptions): RequestOptions;
|
59 | export declare function configureRequestUrl(url: URL, options: RequestOptions): void;
|
60 | export 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 | }
|
73 | export declare function safeGetHeader(response: any, headerKey: string): any;
|
74 | export declare function configureRequestOptions(options: RequestOptions, token?: string | null, method?: "GET" | "DELETE" | "PUT" | "POST"): RequestOptions;
|
75 | export declare function safeStringifyJson(data: any, skippedNames?: Set<string>): string;
|
76 | export {};
|