client.d.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { URL } from 'url'
  2. import Dispatcher from './dispatcher'
  3. import buildConnector from './connector'
  4. import TClientStats from './client-stats'
  5. type ClientConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
  6. /**
  7. * A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default.
  8. */
  9. export class Client extends Dispatcher {
  10. constructor (url: string | URL, options?: Client.Options)
  11. /** Property to get and set the pipelining factor. */
  12. pipelining: number
  13. /** `true` after `client.close()` has been called. */
  14. closed: boolean
  15. /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */
  16. destroyed: boolean
  17. /** Aggregate stats for a Client. */
  18. readonly stats: TClientStats
  19. // Override dispatcher APIs.
  20. override connect (
  21. options: ClientConnectOptions
  22. ): Promise<Dispatcher.ConnectData>
  23. override connect (
  24. options: ClientConnectOptions,
  25. callback: (err: Error | null, data: Dispatcher.ConnectData) => void
  26. ): void
  27. }
  28. export declare namespace Client {
  29. export interface OptionsInterceptors {
  30. Client: readonly Dispatcher.DispatchInterceptor[];
  31. }
  32. export interface Options {
  33. /** TODO */
  34. interceptors?: OptionsInterceptors;
  35. /** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
  36. maxHeaderSize?: number;
  37. /** The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */
  38. headersTimeout?: number;
  39. /** @deprecated unsupported socketTimeout, use headersTimeout & bodyTimeout instead */
  40. socketTimeout?: never;
  41. /** @deprecated unsupported requestTimeout, use headersTimeout & bodyTimeout instead */
  42. requestTimeout?: never;
  43. /** TODO */
  44. connectTimeout?: number;
  45. /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `300e3` milliseconds (300s). */
  46. bodyTimeout?: number;
  47. /** @deprecated unsupported idleTimeout, use keepAliveTimeout instead */
  48. idleTimeout?: never;
  49. /** @deprecated unsupported keepAlive, use pipelining=0 instead */
  50. keepAlive?: never;
  51. /** the timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. Default: `4e3` milliseconds (4s). */
  52. keepAliveTimeout?: number;
  53. /** @deprecated unsupported maxKeepAliveTimeout, use keepAliveMaxTimeout instead */
  54. maxKeepAliveTimeout?: never;
  55. /** the maximum allowed `idleTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
  56. keepAliveMaxTimeout?: number;
  57. /** A number of milliseconds subtracted from server *keep-alive* hints when overriding `idleTimeout` to account for timing inaccuracies caused by e.g. transport latency. Default: `1e3` milliseconds (1s). */
  58. keepAliveTimeoutThreshold?: number;
  59. /** TODO */
  60. socketPath?: string;
  61. /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */
  62. pipelining?: number;
  63. /** @deprecated use the connect option instead */
  64. tls?: never;
  65. /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
  66. strictContentLength?: boolean;
  67. /** TODO */
  68. maxCachedSessions?: number;
  69. /** TODO */
  70. connect?: Partial<buildConnector.BuildOptions> | buildConnector.connector;
  71. /** TODO */
  72. maxRequestsPerClient?: number;
  73. /** TODO */
  74. localAddress?: string;
  75. /** Max response body size in bytes, -1 is disabled */
  76. maxResponseSize?: number;
  77. /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
  78. autoSelectFamily?: boolean;
  79. /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
  80. autoSelectFamilyAttemptTimeout?: number;
  81. /**
  82. * @description Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
  83. * @default false
  84. */
  85. allowH2?: boolean;
  86. /**
  87. * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
  88. * @default 100
  89. */
  90. maxConcurrentStreams?: number;
  91. }
  92. export interface SocketInfo {
  93. localAddress?: string
  94. localPort?: number
  95. remoteAddress?: string
  96. remotePort?: number
  97. remoteFamily?: string
  98. timeout?: number
  99. bytesWritten?: number
  100. bytesRead?: number
  101. }
  102. }
  103. export default Client