h2c-client.d.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { URL } from 'url'
  2. import Dispatcher from './dispatcher'
  3. import buildConnector from './connector'
  4. type H2ClientOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
  5. /**
  6. * A basic H2C client, mapped on top a single TCP connection. Pipelining is disabled by default.
  7. */
  8. export class H2CClient extends Dispatcher {
  9. constructor (url: string | URL, options?: H2CClient.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. // Override dispatcher APIs.
  17. override connect (
  18. options: H2ClientOptions
  19. ): Promise<Dispatcher.ConnectData>
  20. override connect (
  21. options: H2ClientOptions,
  22. callback: (err: Error | null, data: Dispatcher.ConnectData) => void
  23. ): void
  24. }
  25. export declare namespace H2CClient {
  26. export interface Options {
  27. /** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
  28. maxHeaderSize?: number;
  29. /** 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). */
  30. headersTimeout?: number;
  31. /** TODO */
  32. connectTimeout?: number;
  33. /** 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). */
  34. bodyTimeout?: number;
  35. /** 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). */
  36. keepAliveTimeout?: number;
  37. /** the maximum allowed `idleTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
  38. keepAliveMaxTimeout?: number;
  39. /** 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). */
  40. keepAliveTimeoutThreshold?: number;
  41. /** TODO */
  42. socketPath?: string;
  43. /** 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`. */
  44. pipelining?: number;
  45. /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
  46. strictContentLength?: boolean;
  47. /** TODO */
  48. maxCachedSessions?: number;
  49. /** TODO */
  50. connect?: Omit<Partial<buildConnector.BuildOptions>, 'allowH2'> | buildConnector.connector;
  51. /** TODO */
  52. maxRequestsPerClient?: number;
  53. /** TODO */
  54. localAddress?: string;
  55. /** Max response body size in bytes, -1 is disabled */
  56. maxResponseSize?: number;
  57. /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
  58. autoSelectFamily?: boolean;
  59. /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
  60. autoSelectFamilyAttemptTimeout?: number;
  61. /**
  62. * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
  63. * @default 100
  64. */
  65. maxConcurrentStreams?: number
  66. }
  67. }
  68. export default H2CClient