client.d.ts 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { URL } from 'url'
  2. import { TlsOptions } from 'tls'
  3. import Dispatcher from './dispatcher'
  4. import buildConnector from "./connector";
  5. /**
  6. * A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default.
  7. */
  8. export class Client extends Dispatcher {
  9. constructor(url: string | URL, options?: Client.Options);
  10. /** Property to get and set the pipelining factor. */
  11. pipelining: number;
  12. /** `true` after `client.close()` has been called. */
  13. closed: boolean;
  14. /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */
  15. destroyed: boolean;
  16. }
  17. export declare namespace Client {
  18. export interface OptionsInterceptors {
  19. Client: readonly Dispatcher.DispatchInterceptor[];
  20. }
  21. export interface Options {
  22. /** TODO */
  23. interceptors?: OptionsInterceptors;
  24. /** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
  25. maxHeaderSize?: number;
  26. /** 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). */
  27. headersTimeout?: number;
  28. /** @deprecated unsupported socketTimeout, use headersTimeout & bodyTimeout instead */
  29. socketTimeout?: never;
  30. /** @deprecated unsupported requestTimeout, use headersTimeout & bodyTimeout instead */
  31. requestTimeout?: never;
  32. /** TODO */
  33. connectTimeout?: number;
  34. /** 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). */
  35. bodyTimeout?: number;
  36. /** @deprecated unsupported idleTimeout, use keepAliveTimeout instead */
  37. idleTimeout?: never;
  38. /** @deprecated unsupported keepAlive, use pipelining=0 instead */
  39. keepAlive?: never;
  40. /** 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). */
  41. keepAliveTimeout?: number;
  42. /** @deprecated unsupported maxKeepAliveTimeout, use keepAliveMaxTimeout instead */
  43. maxKeepAliveTimeout?: never;
  44. /** the maximum allowed `idleTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
  45. keepAliveMaxTimeout?: number;
  46. /** 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). */
  47. keepAliveTimeoutThreshold?: number;
  48. /** TODO */
  49. socketPath?: string;
  50. /** 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`. */
  51. pipelining?: number;
  52. /** @deprecated use the connect option instead */
  53. tls?: never;
  54. /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
  55. strictContentLength?: boolean;
  56. /** TODO */
  57. maxCachedSessions?: number;
  58. /** TODO */
  59. maxRedirections?: number;
  60. /** TODO */
  61. connect?: buildConnector.BuildOptions | buildConnector.connector;
  62. /** TODO */
  63. maxRequestsPerClient?: number;
  64. /** TODO */
  65. localAddress?: string;
  66. /** Max response body size in bytes, -1 is disabled */
  67. maxResponseSize?: number;
  68. /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
  69. autoSelectFamily?: boolean;
  70. /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
  71. autoSelectFamilyAttemptTimeout?: number;
  72. /**
  73. * @description Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
  74. * @default false
  75. */
  76. allowH2?: boolean;
  77. /**
  78. * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overriden by a SETTINGS remote frame.
  79. * @default 100
  80. */
  81. maxConcurrentStreams?: number
  82. }
  83. export interface SocketInfo {
  84. localAddress?: string
  85. localPort?: number
  86. remoteAddress?: string
  87. remotePort?: number
  88. remoteFamily?: string
  89. timeout?: number
  90. bytesWritten?: number
  91. bytesRead?: number
  92. }
  93. }
  94. export default Client;