index.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. /// <reference types="node" />
  4. /// <reference types="node" />
  5. import * as net from 'net';
  6. import * as tls from 'tls';
  7. import * as http from 'http';
  8. import { Agent, AgentConnectOpts } from 'agent-base';
  9. import { URL } from 'url';
  10. import type { OutgoingHttpHeaders } from 'http';
  11. type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
  12. type ConnectOptsMap = {
  13. http: Omit<net.TcpNetConnectOpts, 'host' | 'port'>;
  14. https: Omit<tls.ConnectionOptions, 'host' | 'port'>;
  15. };
  16. type ConnectOpts<T> = {
  17. [P in keyof ConnectOptsMap]: Protocol<T> extends P ? ConnectOptsMap[P] : never;
  18. }[keyof ConnectOptsMap];
  19. export type HttpProxyAgentOptions<T> = ConnectOpts<T> & http.AgentOptions & {
  20. headers?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
  21. };
  22. interface HttpProxyAgentClientRequest extends http.ClientRequest {
  23. outputData?: {
  24. data: string;
  25. }[];
  26. _header?: string | null;
  27. _implicitHeader(): void;
  28. }
  29. /**
  30. * The `HttpProxyAgent` implements an HTTP Agent subclass that connects
  31. * to the specified "HTTP proxy server" in order to proxy HTTP requests.
  32. */
  33. export declare class HttpProxyAgent<Uri extends string> extends Agent {
  34. static protocols: readonly ["http", "https"];
  35. readonly proxy: URL;
  36. proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
  37. connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
  38. constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>);
  39. addRequest(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): void;
  40. setRequestProps(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): void;
  41. connect(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): Promise<net.Socket>;
  42. }
  43. export {};
  44. //# sourceMappingURL=index.d.ts.map