UNPKG

3.58 kBTypeScriptView Raw
1/// <reference types="node" />
2import { EventEmitter } from "events";
3import { OutgoingHttpHeaders, RequestOptions } from "http";
4import { Transform } from "stream";
5import { CancellationToken } from "./CancellationToken";
6import { ProgressInfo } from "./ProgressCallbackTransform";
7export { CancellationToken, CancellationError } from "./CancellationToken";
8export { ProgressCallbackTransform, ProgressInfo } from "./ProgressCallbackTransform";
9export interface RequestHeaders extends OutgoingHttpHeaders {
10 [key: string]: string;
11}
12export interface RequestOptionsEx extends RequestOptions {
13}
14export interface Response extends EventEmitter {
15 statusCode?: number;
16 statusMessage?: string;
17 headers: any;
18 setEncoding(encoding: string): void;
19}
20export interface DownloadOptions {
21 readonly headers?: OutgoingHttpHeaders | null;
22 readonly skipDirCreation?: boolean;
23 readonly sha2?: string | null;
24 readonly sha512?: string | null;
25 readonly cancellationToken: CancellationToken;
26 onProgress?(progress: ProgressInfo): void;
27}
28export declare class HttpError extends Error {
29 readonly response: {
30 statusMessage?: string | undefined;
31 statusCode?: number | undefined;
32 headers?: {
33 [key: string]: Array<string>;
34 } | undefined;
35 };
36 description: any | null;
37 constructor(response: {
38 statusMessage?: string | undefined;
39 statusCode?: number | undefined;
40 headers?: {
41 [key: string]: Array<string>;
42 } | undefined;
43 }, description?: any | null);
44}
45export declare function parseJson(result: Promise<string | null>): Promise<any>;
46export declare abstract class HttpExecutor<REQUEST> {
47 protected readonly maxRedirects: number;
48 request(options: RequestOptions, cancellationToken?: CancellationToken, data?: {
49 [name: string]: any;
50 } | null): Promise<string | null>;
51 protected abstract doApiRequest(options: RequestOptions, cancellationToken: CancellationToken, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void, redirectCount: number): Promise<string>;
52 protected handleResponse(response: Response, options: RequestOptionsEx, cancellationToken: CancellationToken, resolve: (data?: any) => void, reject: (error: Error) => void, redirectCount: number, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void): void;
53 protected abstract doRequest(options: any, callback: (response: any) => void): any;
54 protected doDownload(requestOptions: any, destination: string, redirectCount: number, options: DownloadOptions, callback: (error: Error | null) => void, onCancel: (callback: () => void) => void): void;
55 protected addTimeOutHandler(request: any, callback: (error: Error) => void): void;
56}
57export declare function configureRequestOptionsFromUrl(url: string, options: RequestOptions): RequestOptions;
58export declare class DigestTransform extends Transform {
59 private readonly expected;
60 private readonly algorithm;
61 private readonly encoding;
62 private readonly digester;
63 constructor(expected: string, algorithm: string, encoding: "hex" | "base64" | "latin1");
64 _transform(chunk: any, encoding: string, callback: any): void;
65 _flush(callback: any): void;
66}
67export declare function safeGetHeader(response: any, headerKey: string): any;
68export declare function configureRequestOptions(options: RequestOptions, token?: string | null, method?: "GET" | "DELETE" | "PUT"): RequestOptions;
69export declare function dumpRequestOptions(options: RequestOptions): string;