httpExecutor.d.ts 3.4 KB

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