index.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 http from 'http';
  7. import { Readable } from 'stream';
  8. import { URL } from 'url';
  9. import { Agent, AgentConnectOpts } from 'agent-base';
  10. import { HttpProxyAgentOptions } from 'http-proxy-agent';
  11. import { HttpsProxyAgentOptions } from 'https-proxy-agent';
  12. import { SocksProxyAgentOptions } from 'socks-proxy-agent';
  13. import { protocols as gProtocols, ProtocolOpts as GetUriOptions } from 'get-uri';
  14. import { FindProxyForURL, PacResolverOptions } from 'pac-resolver';
  15. type Protocols = keyof typeof gProtocols;
  16. type Protocol<T> = T extends `pac+${infer P}:${infer _}` ? P : T extends `${infer P}:${infer _}` ? P : never;
  17. export type PacProxyAgentOptions<T> = http.AgentOptions & PacResolverOptions & GetUriOptions<`${Protocol<T>}:`> & HttpProxyAgentOptions<''> & HttpsProxyAgentOptions<''> & SocksProxyAgentOptions & {
  18. fallbackToDirect?: boolean;
  19. };
  20. /**
  21. * The `PacProxyAgent` class.
  22. *
  23. * A few different "protocol" modes are supported (supported protocols are
  24. * backed by the `get-uri` module):
  25. *
  26. * - "pac+data", "data" - refers to an embedded "data:" URI
  27. * - "pac+file", "file" - refers to a local file
  28. * - "pac+ftp", "ftp" - refers to a file located on an FTP server
  29. * - "pac+http", "http" - refers to an HTTP endpoint
  30. * - "pac+https", "https" - refers to an HTTPS endpoint
  31. */
  32. export declare class PacProxyAgent<Uri extends string> extends Agent {
  33. static readonly protocols: `pac+${Protocols}`[];
  34. uri: URL;
  35. opts: PacProxyAgentOptions<Uri>;
  36. cache?: Readable;
  37. resolver?: FindProxyForURL;
  38. resolverHash: string;
  39. resolverPromise?: Promise<FindProxyForURL>;
  40. constructor(uri: Uri | URL, opts?: PacProxyAgentOptions<Uri>);
  41. private clearResolverPromise;
  42. /**
  43. * Loads the PAC proxy file from the source if necessary, and returns
  44. * a generated `FindProxyForURL()` resolver function to use.
  45. *
  46. * @api private
  47. */
  48. private getResolver;
  49. private loadResolver;
  50. /**
  51. * Loads the contents of the PAC proxy file.
  52. *
  53. * @api private
  54. */
  55. private loadPacFile;
  56. /**
  57. * Called when the node-core HTTP client library is creating a new HTTP request.
  58. */
  59. connect(req: http.ClientRequest, opts: AgentConnectOpts): Promise<http.Agent | net.Socket>;
  60. }
  61. export {};
  62. //# sourceMappingURL=index.d.ts.map