index.d.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 HttpsProxyAgentOptions<T> = ConnectOpts<T> & http.AgentOptions & {
  20. headers?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
  21. };
  22. /**
  23. * The `HttpsProxyAgent` implements an HTTP Agent subclass that connects to
  24. * the specified "HTTP(s) proxy server" in order to proxy HTTPS requests.
  25. *
  26. * Outgoing HTTP requests are first tunneled through the proxy server using the
  27. * `CONNECT` HTTP request method to establish a connection to the proxy server,
  28. * and then the proxy server connects to the destination target and issues the
  29. * HTTP request from the proxy server.
  30. *
  31. * `https:` requests have their socket connection upgraded to TLS once
  32. * the connection to the proxy server has been established.
  33. */
  34. export declare class HttpsProxyAgent<Uri extends string> extends Agent {
  35. static protocols: readonly ["http", "https"];
  36. readonly proxy: URL;
  37. proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
  38. connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
  39. constructor(proxy: Uri | URL, opts?: HttpsProxyAgentOptions<Uri>);
  40. /**
  41. * Called when the node-core HTTP client library is creating a
  42. * new HTTP request.
  43. */
  44. connect(req: http.ClientRequest, opts: AgentConnectOpts): Promise<net.Socket>;
  45. }
  46. export {};
  47. //# sourceMappingURL=index.d.ts.map