index.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /// <reference types="node" />
  2. import * as http from 'http';
  3. import LRUCache from 'lru-cache';
  4. import { Agent, AgentConnectOpts } from 'agent-base';
  5. import { PacProxyAgentOptions } from 'pac-proxy-agent';
  6. import { HttpProxyAgentOptions } from 'http-proxy-agent';
  7. import { HttpsProxyAgentOptions } from 'https-proxy-agent';
  8. import { SocksProxyAgentOptions } from 'socks-proxy-agent';
  9. declare const PROTOCOLS: readonly ["http", "https", "socks", "socks4", "socks4a", "socks5", "socks5h", ...("pac+http" | "pac+https" | "pac+data" | "pac+file" | "pac+ftp")[]];
  10. type ValidProtocol = (typeof PROTOCOLS)[number];
  11. type AgentConstructor = new (...args: never[]) => Agent;
  12. type GetProxyForUrlCallback = (url: string) => string;
  13. /**
  14. * Supported proxy types.
  15. */
  16. export declare const proxies: {
  17. [P in ValidProtocol]: [AgentConstructor, AgentConstructor];
  18. };
  19. export type ProxyAgentOptions = HttpProxyAgentOptions<''> & HttpsProxyAgentOptions<''> & SocksProxyAgentOptions & PacProxyAgentOptions<''> & {
  20. /**
  21. * Default `http.Agent` instance to use when no proxy is
  22. * configured for a request. Defaults to a new `http.Agent()`
  23. * instance with the proxy agent options passed in.
  24. */
  25. httpAgent?: http.Agent;
  26. /**
  27. * Default `http.Agent` instance to use when no proxy is
  28. * configured for a request. Defaults to a new `https.Agent()`
  29. * instance with the proxy agent options passed in.
  30. */
  31. httpsAgent?: http.Agent;
  32. /**
  33. * A callback for dynamic provision of proxy for url.
  34. * Defaults to standard proxy environment variables,
  35. * see https://www.npmjs.com/package/proxy-from-env for details
  36. */
  37. getProxyForUrl?: GetProxyForUrlCallback;
  38. };
  39. /**
  40. * Uses the appropriate `Agent` subclass based off of the "proxy"
  41. * environment variables that are currently set.
  42. *
  43. * An LRU cache is used, to prevent unnecessary creation of proxy
  44. * `http.Agent` instances.
  45. */
  46. export declare class ProxyAgent extends Agent {
  47. /**
  48. * Cache for `Agent` instances.
  49. */
  50. cache: LRUCache<string, Agent>;
  51. connectOpts?: ProxyAgentOptions;
  52. httpAgent: http.Agent;
  53. httpsAgent: http.Agent;
  54. getProxyForUrl: GetProxyForUrlCallback;
  55. constructor(opts?: ProxyAgentOptions);
  56. connect(req: http.ClientRequest, opts: AgentConnectOpts): Promise<http.Agent>;
  57. destroy(): void;
  58. }
  59. export {};
  60. //# sourceMappingURL=index.d.ts.map