client.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { URL } from 'url'
  2. import { TlsOptions } from 'tls'
  3. import Dispatcher from './dispatcher'
  4. import buildConnector from "./connector";
  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. // Override dispatcher APIs.
  18. override connect(
  19. options: ClientConnectOptions
  20. ): Promise<Dispatcher.ConnectData>;
  21. override connect(
  22. options: ClientConnectOptions,
  23. callback: (err: Error | null, data: Dispatcher.ConnectData) => void
  24. ): void;
  25. }
  26. export declare namespace Client {
  27. export interface OptionsInterceptors {
  28. Client: readonly Dispatcher.DispatchInterceptor[];
  29. }
  30. export interface Options {
  31. /** TODO */
  32. interceptors?: OptionsInterceptors;
  33. /** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
  34. maxHeaderSize?: number;
  35. /** 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). */
  36. headersTimeout?: number;
  37. /** @deprecated unsupported socketTimeout, use headersTimeout & bodyTimeout instead */
  38. socketTimeout?: never;
  39. /** @deprecated unsupported requestTimeout, use headersTimeout & bodyTimeout instead */
  40. requestTimeout?: never;
  41. /** TODO */
  42. connectTimeout?: number;
  43. /** 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). */
  44. bodyTimeout?: number;
  45. /** @deprecated unsupported idleTimeout, use keepAliveTimeout instead */
  46. idleTimeout?: never;
  47. /** @deprecated unsupported keepAlive, use pipelining=0 instead */
  48. keepAlive?: never;
  49. /** 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). */
  50. keepAliveTimeout?: number;
  51. /** @deprecated unsupported maxKeepAliveTimeout, use keepAliveMaxTimeout instead */
  52. maxKeepAliveTimeout?: never;
  53. /** the maximum allowed `idleTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
  54. keepAliveMaxTimeout?: number;
  55. /** 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). */
  56. keepAliveTimeoutThreshold?: number;
  57. /** TODO */
  58. socketPath?: string;
  59. /** 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`. */
  60. pipelining?: number;
  61. /** @deprecated use the connect option instead */
  62. tls?: never;
  63. /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
  64. strictContentLength?: boolean;
  65. /** TODO */
  66. maxCachedSessions?: number;
  67. /** TODO */
  68. maxRedirections?: number;
  69. /** TODO */
  70. connect?: 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;