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