ecc18c0e82ddf46ea4d582c79837e6e55629741f3de97ef9d15a6dcc63f72a9dff3907a3529400a123773a2d4ce4cd867e494ed3037dc3375d8e648aeb2663 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. maxRedirections?: number;
  51. /** TODO */
  52. connect?: Omit<Partial<buildConnector.BuildOptions>, 'allowH2'> | buildConnector.connector;
  53. /** TODO */
  54. maxRequestsPerClient?: number;
  55. /** TODO */
  56. localAddress?: string;
  57. /** Max response body size in bytes, -1 is disabled */
  58. maxResponseSize?: number;
  59. /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
  60. autoSelectFamily?: boolean;
  61. /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
  62. autoSelectFamilyAttemptTimeout?: number;
  63. /**
  64. * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
  65. * @default 100
  66. */
  67. maxConcurrentStreams?: number
  68. }
  69. }
  70. export default H2CClient