index.d.ts 1.7 KB

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