index.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import * as http from 'http';
  2. import * as https from 'https';
  3. import * as net from 'net';
  4. interface PlainObject {
  5. [key: string]: any;
  6. }
  7. declare class _HttpAgent extends http.Agent {
  8. constructor(opts?: AgentKeepAlive.HttpOptions);
  9. readonly statusChanged: boolean;
  10. createConnection(options: net.NetConnectOpts, cb?: Function): net.Socket;
  11. createSocket(req: http.IncomingMessage, options: http.RequestOptions, cb: Function): void;
  12. getCurrentStatus(): AgentKeepAlive.AgentStatus;
  13. }
  14. interface Constants {
  15. CURRENT_ID: Symbol;
  16. CREATE_ID: Symbol;
  17. INIT_SOCKET: Symbol;
  18. CREATE_HTTPS_CONNECTION: Symbol;
  19. SOCKET_CREATED_TIME: Symbol;
  20. SOCKET_NAME: Symbol;
  21. SOCKET_REQUEST_COUNT: Symbol;
  22. SOCKET_REQUEST_FINISHED_COUNT: Symbol;
  23. }
  24. /**
  25. * @deprecated instead use `import { HttpAgent } from 'agentkeepalive'; or `const HttpAgent = require('agentkeepalive').HttpAgent;`
  26. */
  27. declare class AgentKeepAlive extends _HttpAgent {}
  28. declare namespace AgentKeepAlive {
  29. export interface AgentStatus {
  30. createSocketCount: number;
  31. createSocketErrorCount: number;
  32. closeSocketCount: number;
  33. errorSocketCount: number;
  34. timeoutSocketCount: number;
  35. requestCount: number;
  36. freeSockets: PlainObject;
  37. sockets: PlainObject;
  38. requests: PlainObject;
  39. }
  40. interface CommonHttpOption {
  41. keepAlive?: boolean | undefined;
  42. freeSocketTimeout?: number | undefined;
  43. freeSocketKeepAliveTimeout?: number | undefined;
  44. timeout?: number | undefined;
  45. socketActiveTTL?: number | undefined;
  46. }
  47. export interface HttpOptions extends http.AgentOptions, CommonHttpOption { }
  48. export interface HttpsOptions extends https.AgentOptions, CommonHttpOption { }
  49. export class HttpAgent extends _HttpAgent {}
  50. export class HttpsAgent extends https.Agent {
  51. constructor(opts?: HttpsOptions);
  52. readonly statusChanged: boolean;
  53. createConnection(options: net.NetConnectOpts, cb?: Function): net.Socket;
  54. createSocket(req: http.IncomingMessage, options: http.RequestOptions, cb: Function): void;
  55. getCurrentStatus(): AgentStatus;
  56. }
  57. export const constants: Constants;
  58. }
  59. export = AgentKeepAlive;