@types/node 16.3.3 → 16.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/http2.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * The `http2` module provides an implementation of the [HTTP/2](https://tools.ietf.org/html/rfc7540) protocol. It
3
+ * can be accessed using:
4
+ *
5
+ * ```js
6
+ * const http2 = require('http2');
7
+ * ```
8
+ * @since v8.4.0
9
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/http2.js)
10
+ */
1
11
  declare module 'http2' {
2
12
  import EventEmitter = require('node:events');
3
13
  import * as fs from 'node:fs';
@@ -5,35 +15,24 @@ declare module 'http2' {
5
15
  import * as stream from 'node:stream';
6
16
  import * as tls from 'node:tls';
7
17
  import * as url from 'node:url';
8
-
9
- import {
10
- IncomingHttpHeaders as Http1IncomingHttpHeaders,
11
- OutgoingHttpHeaders,
12
- IncomingMessage,
13
- ServerResponse,
14
- } from 'node:http';
18
+ import { IncomingHttpHeaders as Http1IncomingHttpHeaders, OutgoingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
15
19
  export { OutgoingHttpHeaders } from 'node:http';
16
-
17
20
  export interface IncomingHttpStatusHeader {
18
- ":status"?: number | undefined;
21
+ ':status'?: number | undefined;
19
22
  }
20
-
21
23
  export interface IncomingHttpHeaders extends Http1IncomingHttpHeaders {
22
- ":path"?: string | undefined;
23
- ":method"?: string | undefined;
24
- ":authority"?: string | undefined;
25
- ":scheme"?: string | undefined;
24
+ ':path'?: string | undefined;
25
+ ':method'?: string | undefined;
26
+ ':authority'?: string | undefined;
27
+ ':scheme'?: string | undefined;
26
28
  }
27
-
28
29
  // Http2Stream
29
-
30
30
  export interface StreamPriorityOptions {
31
31
  exclusive?: boolean | undefined;
32
32
  parent?: number | undefined;
33
33
  weight?: number | undefined;
34
34
  silent?: boolean | undefined;
35
35
  }
36
-
37
36
  export interface StreamState {
38
37
  localWindowSize?: number | undefined;
39
38
  state?: number | undefined;
@@ -42,200 +41,530 @@ declare module 'http2' {
42
41
  sumDependencyWeight?: number | undefined;
43
42
  weight?: number | undefined;
44
43
  }
45
-
46
44
  export interface ServerStreamResponseOptions {
47
45
  endStream?: boolean | undefined;
48
46
  waitForTrailers?: boolean | undefined;
49
47
  }
50
-
51
48
  export interface StatOptions {
52
49
  offset: number;
53
50
  length: number;
54
51
  }
55
-
56
52
  export interface ServerStreamFileResponseOptions {
57
53
  statCheck?(stats: fs.Stats, headers: OutgoingHttpHeaders, statOptions: StatOptions): void | boolean;
58
54
  waitForTrailers?: boolean | undefined;
59
55
  offset?: number | undefined;
60
56
  length?: number | undefined;
61
57
  }
62
-
63
58
  export interface ServerStreamFileResponseOptionsWithError extends ServerStreamFileResponseOptions {
64
59
  onError?(err: NodeJS.ErrnoException): void;
65
60
  }
66
-
67
61
  export interface Http2Stream extends stream.Duplex {
62
+ /**
63
+ * Set to `true` if the `Http2Stream` instance was aborted abnormally. When set,
64
+ * the `'aborted'` event will have been emitted.
65
+ * @since v8.4.0
66
+ */
68
67
  readonly aborted: boolean;
68
+ /**
69
+ * This property shows the number of characters currently buffered to be written.
70
+ * See `net.Socket.bufferSize` for details.
71
+ * @since v11.2.0, v10.16.0
72
+ */
69
73
  readonly bufferSize: number;
74
+ /**
75
+ * Set to `true` if the `Http2Stream` instance has been closed.
76
+ * @since v9.4.0
77
+ */
70
78
  readonly closed: boolean;
79
+ /**
80
+ * Set to `true` if the `Http2Stream` instance has been destroyed and is no longer
81
+ * usable.
82
+ * @since v8.4.0
83
+ */
71
84
  readonly destroyed: boolean;
72
85
  /**
73
- * Set the true if the END_STREAM flag was set in the request or response HEADERS frame received,
74
- * indicating that no additional data should be received and the readable side of the Http2Stream will be closed.
86
+ * Set the `true` if the `END_STREAM` flag was set in the request or response
87
+ * HEADERS frame received, indicating that no additional data should be received
88
+ * and the readable side of the `Http2Stream` will be closed.
89
+ * @since v10.11.0
75
90
  */
76
91
  readonly endAfterHeaders: boolean;
92
+ /**
93
+ * The numeric stream identifier of this `Http2Stream` instance. Set to `undefined`if the stream identifier has not yet been assigned.
94
+ * @since v8.4.0
95
+ */
77
96
  readonly id?: number | undefined;
97
+ /**
98
+ * Set to `true` if the `Http2Stream` instance has not yet been assigned a
99
+ * numeric stream identifier.
100
+ * @since v9.4.0
101
+ */
78
102
  readonly pending: boolean;
103
+ /**
104
+ * Set to the `RST_STREAM` `error code` reported when the `Http2Stream` is
105
+ * destroyed after either receiving an `RST_STREAM` frame from the connected peer,
106
+ * calling `http2stream.close()`, or `http2stream.destroy()`. Will be`undefined` if the `Http2Stream` has not been closed.
107
+ * @since v8.4.0
108
+ */
79
109
  readonly rstCode: number;
110
+ /**
111
+ * An object containing the outbound headers sent for this `Http2Stream`.
112
+ * @since v9.5.0
113
+ */
80
114
  readonly sentHeaders: OutgoingHttpHeaders;
115
+ /**
116
+ * An array of objects containing the outbound informational (additional) headers
117
+ * sent for this `Http2Stream`.
118
+ * @since v9.5.0
119
+ */
81
120
  readonly sentInfoHeaders?: OutgoingHttpHeaders[] | undefined;
121
+ /**
122
+ * An object containing the outbound trailers sent for this `HttpStream`.
123
+ * @since v9.5.0
124
+ */
82
125
  readonly sentTrailers?: OutgoingHttpHeaders | undefined;
126
+ /**
127
+ * A reference to the `Http2Session` instance that owns this `Http2Stream`. The
128
+ * value will be `undefined` after the `Http2Stream` instance is destroyed.
129
+ * @since v8.4.0
130
+ */
83
131
  readonly session: Http2Session;
132
+ /**
133
+ * Provides miscellaneous information about the current state of the`Http2Stream`.
134
+ *
135
+ * A current state of this `Http2Stream`.
136
+ * @since v8.4.0
137
+ */
84
138
  readonly state: StreamState;
85
-
139
+ /**
140
+ * Closes the `Http2Stream` instance by sending an `RST_STREAM` frame to the
141
+ * connected HTTP/2 peer.
142
+ * @since v8.4.0
143
+ * @param code Unsigned 32-bit integer identifying the error code.
144
+ * @param callback An optional function registered to listen for the `'close'` event.
145
+ */
86
146
  close(code?: number, callback?: () => void): void;
147
+ /**
148
+ * Updates the priority for this `Http2Stream` instance.
149
+ * @since v8.4.0
150
+ */
87
151
  priority(options: StreamPriorityOptions): void;
152
+ /**
153
+ * ```js
154
+ * const http2 = require('http2');
155
+ * const client = http2.connect('http://example.org:8000');
156
+ * const { NGHTTP2_CANCEL } = http2.constants;
157
+ * const req = client.request({ ':path': '/' });
158
+ *
159
+ * // Cancel the stream if there's no activity after 5 seconds
160
+ * req.setTimeout(5000, () => req.close(NGHTTP2_CANCEL));
161
+ * ```
162
+ * @since v8.4.0
163
+ */
88
164
  setTimeout(msecs: number, callback?: () => void): void;
165
+ /**
166
+ * Sends a trailing `HEADERS` frame to the connected HTTP/2 peer. This method
167
+ * will cause the `Http2Stream` to be immediately closed and must only be
168
+ * called after the `'wantTrailers'` event has been emitted. When sending a
169
+ * request or sending a response, the `options.waitForTrailers` option must be set
170
+ * in order to keep the `Http2Stream` open after the final `DATA` frame so that
171
+ * trailers can be sent.
172
+ *
173
+ * ```js
174
+ * const http2 = require('http2');
175
+ * const server = http2.createServer();
176
+ * server.on('stream', (stream) => {
177
+ * stream.respond(undefined, { waitForTrailers: true });
178
+ * stream.on('wantTrailers', () => {
179
+ * stream.sendTrailers({ xyz: 'abc' });
180
+ * });
181
+ * stream.end('Hello World');
182
+ * });
183
+ * ```
184
+ *
185
+ * The HTTP/1 specification forbids trailers from containing HTTP/2 pseudo-header
186
+ * fields (e.g. `':method'`, `':path'`, etc).
187
+ * @since v10.0.0
188
+ */
89
189
  sendTrailers(headers: OutgoingHttpHeaders): void;
90
-
91
- addListener(event: "aborted", listener: () => void): this;
92
- addListener(event: "close", listener: () => void): this;
93
- addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
94
- addListener(event: "drain", listener: () => void): this;
95
- addListener(event: "end", listener: () => void): this;
96
- addListener(event: "error", listener: (err: Error) => void): this;
97
- addListener(event: "finish", listener: () => void): this;
98
- addListener(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
99
- addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
100
- addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
101
- addListener(event: "streamClosed", listener: (code: number) => void): this;
102
- addListener(event: "timeout", listener: () => void): this;
103
- addListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
104
- addListener(event: "wantTrailers", listener: () => void): this;
190
+ addListener(event: 'aborted', listener: () => void): this;
191
+ addListener(event: 'close', listener: () => void): this;
192
+ addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
193
+ addListener(event: 'drain', listener: () => void): this;
194
+ addListener(event: 'end', listener: () => void): this;
195
+ addListener(event: 'error', listener: (err: Error) => void): this;
196
+ addListener(event: 'finish', listener: () => void): this;
197
+ addListener(event: 'frameError', listener: (frameType: number, errorCode: number) => void): this;
198
+ addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
199
+ addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
200
+ addListener(event: 'streamClosed', listener: (code: number) => void): this;
201
+ addListener(event: 'timeout', listener: () => void): this;
202
+ addListener(event: 'trailers', listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
203
+ addListener(event: 'wantTrailers', listener: () => void): this;
105
204
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
106
-
107
- emit(event: "aborted"): boolean;
108
- emit(event: "close"): boolean;
109
- emit(event: "data", chunk: Buffer | string): boolean;
110
- emit(event: "drain"): boolean;
111
- emit(event: "end"): boolean;
112
- emit(event: "error", err: Error): boolean;
113
- emit(event: "finish"): boolean;
114
- emit(event: "frameError", frameType: number, errorCode: number): boolean;
115
- emit(event: "pipe", src: stream.Readable): boolean;
116
- emit(event: "unpipe", src: stream.Readable): boolean;
117
- emit(event: "streamClosed", code: number): boolean;
118
- emit(event: "timeout"): boolean;
119
- emit(event: "trailers", trailers: IncomingHttpHeaders, flags: number): boolean;
120
- emit(event: "wantTrailers"): boolean;
205
+ emit(event: 'aborted'): boolean;
206
+ emit(event: 'close'): boolean;
207
+ emit(event: 'data', chunk: Buffer | string): boolean;
208
+ emit(event: 'drain'): boolean;
209
+ emit(event: 'end'): boolean;
210
+ emit(event: 'error', err: Error): boolean;
211
+ emit(event: 'finish'): boolean;
212
+ emit(event: 'frameError', frameType: number, errorCode: number): boolean;
213
+ emit(event: 'pipe', src: stream.Readable): boolean;
214
+ emit(event: 'unpipe', src: stream.Readable): boolean;
215
+ emit(event: 'streamClosed', code: number): boolean;
216
+ emit(event: 'timeout'): boolean;
217
+ emit(event: 'trailers', trailers: IncomingHttpHeaders, flags: number): boolean;
218
+ emit(event: 'wantTrailers'): boolean;
121
219
  emit(event: string | symbol, ...args: any[]): boolean;
122
-
123
- on(event: "aborted", listener: () => void): this;
124
- on(event: "close", listener: () => void): this;
125
- on(event: "data", listener: (chunk: Buffer | string) => void): this;
126
- on(event: "drain", listener: () => void): this;
127
- on(event: "end", listener: () => void): this;
128
- on(event: "error", listener: (err: Error) => void): this;
129
- on(event: "finish", listener: () => void): this;
130
- on(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
131
- on(event: "pipe", listener: (src: stream.Readable) => void): this;
132
- on(event: "unpipe", listener: (src: stream.Readable) => void): this;
133
- on(event: "streamClosed", listener: (code: number) => void): this;
134
- on(event: "timeout", listener: () => void): this;
135
- on(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
136
- on(event: "wantTrailers", listener: () => void): this;
220
+ on(event: 'aborted', listener: () => void): this;
221
+ on(event: 'close', listener: () => void): this;
222
+ on(event: 'data', listener: (chunk: Buffer | string) => void): this;
223
+ on(event: 'drain', listener: () => void): this;
224
+ on(event: 'end', listener: () => void): this;
225
+ on(event: 'error', listener: (err: Error) => void): this;
226
+ on(event: 'finish', listener: () => void): this;
227
+ on(event: 'frameError', listener: (frameType: number, errorCode: number) => void): this;
228
+ on(event: 'pipe', listener: (src: stream.Readable) => void): this;
229
+ on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
230
+ on(event: 'streamClosed', listener: (code: number) => void): this;
231
+ on(event: 'timeout', listener: () => void): this;
232
+ on(event: 'trailers', listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
233
+ on(event: 'wantTrailers', listener: () => void): this;
137
234
  on(event: string | symbol, listener: (...args: any[]) => void): this;
138
-
139
- once(event: "aborted", listener: () => void): this;
140
- once(event: "close", listener: () => void): this;
141
- once(event: "data", listener: (chunk: Buffer | string) => void): this;
142
- once(event: "drain", listener: () => void): this;
143
- once(event: "end", listener: () => void): this;
144
- once(event: "error", listener: (err: Error) => void): this;
145
- once(event: "finish", listener: () => void): this;
146
- once(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
147
- once(event: "pipe", listener: (src: stream.Readable) => void): this;
148
- once(event: "unpipe", listener: (src: stream.Readable) => void): this;
149
- once(event: "streamClosed", listener: (code: number) => void): this;
150
- once(event: "timeout", listener: () => void): this;
151
- once(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
152
- once(event: "wantTrailers", listener: () => void): this;
235
+ once(event: 'aborted', listener: () => void): this;
236
+ once(event: 'close', listener: () => void): this;
237
+ once(event: 'data', listener: (chunk: Buffer | string) => void): this;
238
+ once(event: 'drain', listener: () => void): this;
239
+ once(event: 'end', listener: () => void): this;
240
+ once(event: 'error', listener: (err: Error) => void): this;
241
+ once(event: 'finish', listener: () => void): this;
242
+ once(event: 'frameError', listener: (frameType: number, errorCode: number) => void): this;
243
+ once(event: 'pipe', listener: (src: stream.Readable) => void): this;
244
+ once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
245
+ once(event: 'streamClosed', listener: (code: number) => void): this;
246
+ once(event: 'timeout', listener: () => void): this;
247
+ once(event: 'trailers', listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
248
+ once(event: 'wantTrailers', listener: () => void): this;
153
249
  once(event: string | symbol, listener: (...args: any[]) => void): this;
154
-
155
- prependListener(event: "aborted", listener: () => void): this;
156
- prependListener(event: "close", listener: () => void): this;
157
- prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
158
- prependListener(event: "drain", listener: () => void): this;
159
- prependListener(event: "end", listener: () => void): this;
160
- prependListener(event: "error", listener: (err: Error) => void): this;
161
- prependListener(event: "finish", listener: () => void): this;
162
- prependListener(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
163
- prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
164
- prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
165
- prependListener(event: "streamClosed", listener: (code: number) => void): this;
166
- prependListener(event: "timeout", listener: () => void): this;
167
- prependListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
168
- prependListener(event: "wantTrailers", listener: () => void): this;
250
+ prependListener(event: 'aborted', listener: () => void): this;
251
+ prependListener(event: 'close', listener: () => void): this;
252
+ prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
253
+ prependListener(event: 'drain', listener: () => void): this;
254
+ prependListener(event: 'end', listener: () => void): this;
255
+ prependListener(event: 'error', listener: (err: Error) => void): this;
256
+ prependListener(event: 'finish', listener: () => void): this;
257
+ prependListener(event: 'frameError', listener: (frameType: number, errorCode: number) => void): this;
258
+ prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
259
+ prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
260
+ prependListener(event: 'streamClosed', listener: (code: number) => void): this;
261
+ prependListener(event: 'timeout', listener: () => void): this;
262
+ prependListener(event: 'trailers', listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
263
+ prependListener(event: 'wantTrailers', listener: () => void): this;
169
264
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
170
-
171
- prependOnceListener(event: "aborted", listener: () => void): this;
172
- prependOnceListener(event: "close", listener: () => void): this;
173
- prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
174
- prependOnceListener(event: "drain", listener: () => void): this;
175
- prependOnceListener(event: "end", listener: () => void): this;
176
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
177
- prependOnceListener(event: "finish", listener: () => void): this;
178
- prependOnceListener(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
179
- prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
180
- prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
181
- prependOnceListener(event: "streamClosed", listener: (code: number) => void): this;
182
- prependOnceListener(event: "timeout", listener: () => void): this;
183
- prependOnceListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
184
- prependOnceListener(event: "wantTrailers", listener: () => void): this;
265
+ prependOnceListener(event: 'aborted', listener: () => void): this;
266
+ prependOnceListener(event: 'close', listener: () => void): this;
267
+ prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
268
+ prependOnceListener(event: 'drain', listener: () => void): this;
269
+ prependOnceListener(event: 'end', listener: () => void): this;
270
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
271
+ prependOnceListener(event: 'finish', listener: () => void): this;
272
+ prependOnceListener(event: 'frameError', listener: (frameType: number, errorCode: number) => void): this;
273
+ prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
274
+ prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
275
+ prependOnceListener(event: 'streamClosed', listener: (code: number) => void): this;
276
+ prependOnceListener(event: 'timeout', listener: () => void): this;
277
+ prependOnceListener(event: 'trailers', listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
278
+ prependOnceListener(event: 'wantTrailers', listener: () => void): this;
185
279
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
186
280
  }
187
-
188
281
  export interface ClientHttp2Stream extends Http2Stream {
189
- addListener(event: "continue", listener: () => {}): this;
190
- addListener(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
191
- addListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
192
- addListener(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
282
+ addListener(event: 'continue', listener: () => {}): this;
283
+ addListener(event: 'headers', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
284
+ addListener(event: 'push', listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
285
+ addListener(event: 'response', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
193
286
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
194
-
195
- emit(event: "continue"): boolean;
196
- emit(event: "headers", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
197
- emit(event: "push", headers: IncomingHttpHeaders, flags: number): boolean;
198
- emit(event: "response", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
287
+ emit(event: 'continue'): boolean;
288
+ emit(event: 'headers', headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
289
+ emit(event: 'push', headers: IncomingHttpHeaders, flags: number): boolean;
290
+ emit(event: 'response', headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
199
291
  emit(event: string | symbol, ...args: any[]): boolean;
200
-
201
- on(event: "continue", listener: () => {}): this;
202
- on(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
203
- on(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
204
- on(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
292
+ on(event: 'continue', listener: () => {}): this;
293
+ on(event: 'headers', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
294
+ on(event: 'push', listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
295
+ on(event: 'response', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
205
296
  on(event: string | symbol, listener: (...args: any[]) => void): this;
206
-
207
- once(event: "continue", listener: () => {}): this;
208
- once(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
209
- once(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
210
- once(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
297
+ once(event: 'continue', listener: () => {}): this;
298
+ once(event: 'headers', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
299
+ once(event: 'push', listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
300
+ once(event: 'response', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
211
301
  once(event: string | symbol, listener: (...args: any[]) => void): this;
212
-
213
- prependListener(event: "continue", listener: () => {}): this;
214
- prependListener(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
215
- prependListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
216
- prependListener(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
302
+ prependListener(event: 'continue', listener: () => {}): this;
303
+ prependListener(event: 'headers', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
304
+ prependListener(event: 'push', listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
305
+ prependListener(event: 'response', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
217
306
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
218
-
219
- prependOnceListener(event: "continue", listener: () => {}): this;
220
- prependOnceListener(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
221
- prependOnceListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
222
- prependOnceListener(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
307
+ prependOnceListener(event: 'continue', listener: () => {}): this;
308
+ prependOnceListener(event: 'headers', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
309
+ prependOnceListener(event: 'push', listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
310
+ prependOnceListener(event: 'response', listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
223
311
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
224
312
  }
225
-
226
313
  export interface ServerHttp2Stream extends Http2Stream {
314
+ /**
315
+ * True if headers were sent, false otherwise (read-only).
316
+ * @since v8.4.0
317
+ */
227
318
  readonly headersSent: boolean;
319
+ /**
320
+ * Read-only property mapped to the `SETTINGS_ENABLE_PUSH` flag of the remote
321
+ * client's most recent `SETTINGS` frame. Will be `true` if the remote peer
322
+ * accepts push streams, `false` otherwise. Settings are the same for every`Http2Stream` in the same `Http2Session`.
323
+ * @since v8.4.0
324
+ */
228
325
  readonly pushAllowed: boolean;
326
+ /**
327
+ * Sends an additional informational `HEADERS` frame to the connected HTTP/2 peer.
328
+ * @since v8.4.0
329
+ */
229
330
  additionalHeaders(headers: OutgoingHttpHeaders): void;
331
+ /**
332
+ * Initiates a push stream. The callback is invoked with the new `Http2Stream`instance created for the push stream passed as the second argument, or an`Error` passed as the first argument.
333
+ *
334
+ * ```js
335
+ * const http2 = require('http2');
336
+ * const server = http2.createServer();
337
+ * server.on('stream', (stream) => {
338
+ * stream.respond({ ':status': 200 });
339
+ * stream.pushStream({ ':path': '/' }, (err, pushStream, headers) => {
340
+ * if (err) throw err;
341
+ * pushStream.respond({ ':status': 200 });
342
+ * pushStream.end('some pushed data');
343
+ * });
344
+ * stream.end('some data');
345
+ * });
346
+ * ```
347
+ *
348
+ * Setting the weight of a push stream is not allowed in the `HEADERS` frame. Pass
349
+ * a `weight` value to `http2stream.priority` with the `silent` option set to`true` to enable server-side bandwidth balancing between concurrent streams.
350
+ *
351
+ * Calling `http2stream.pushStream()` from within a pushed stream is not permitted
352
+ * and will throw an error.
353
+ * @since v8.4.0
354
+ * @param callback Callback that is called once the push stream has been initiated.
355
+ */
230
356
  pushStream(headers: OutgoingHttpHeaders, callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void): void;
231
357
  pushStream(headers: OutgoingHttpHeaders, options?: StreamPriorityOptions, callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void): void;
358
+ /**
359
+ * ```js
360
+ * const http2 = require('http2');
361
+ * const server = http2.createServer();
362
+ * server.on('stream', (stream) => {
363
+ * stream.respond({ ':status': 200 });
364
+ * stream.end('some data');
365
+ * });
366
+ * ```
367
+ *
368
+ * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
369
+ * will be emitted immediately after queuing the last chunk of payload data to be
370
+ * sent. The `http2stream.sendTrailers()` method can then be used to sent trailing
371
+ * header fields to the peer.
372
+ *
373
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
374
+ * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
375
+ *
376
+ * ```js
377
+ * const http2 = require('http2');
378
+ * const server = http2.createServer();
379
+ * server.on('stream', (stream) => {
380
+ * stream.respond({ ':status': 200 }, { waitForTrailers: true });
381
+ * stream.on('wantTrailers', () => {
382
+ * stream.sendTrailers({ ABC: 'some value to send' });
383
+ * });
384
+ * stream.end('some data');
385
+ * });
386
+ * ```
387
+ * @since v8.4.0
388
+ */
232
389
  respond(headers?: OutgoingHttpHeaders, options?: ServerStreamResponseOptions): void;
390
+ /**
391
+ * Initiates a response whose data is read from the given file descriptor. No
392
+ * validation is performed on the given file descriptor. If an error occurs while
393
+ * attempting to read data using the file descriptor, the `Http2Stream` will be
394
+ * closed using an `RST_STREAM` frame using the standard `INTERNAL_ERROR` code.
395
+ *
396
+ * When used, the `Http2Stream` object's `Duplex` interface will be closed
397
+ * automatically.
398
+ *
399
+ * ```js
400
+ * const http2 = require('http2');
401
+ * const fs = require('fs');
402
+ *
403
+ * const server = http2.createServer();
404
+ * server.on('stream', (stream) => {
405
+ * const fd = fs.openSync('/some/file', 'r');
406
+ *
407
+ * const stat = fs.fstatSync(fd);
408
+ * const headers = {
409
+ * 'content-length': stat.size,
410
+ * 'last-modified': stat.mtime.toUTCString(),
411
+ * 'content-type': 'text/plain; charset=utf-8'
412
+ * };
413
+ * stream.respondWithFD(fd, headers);
414
+ * stream.on('close', () => fs.closeSync(fd));
415
+ * });
416
+ * ```
417
+ *
418
+ * The optional `options.statCheck` function may be specified to give user code
419
+ * an opportunity to set additional content headers based on the `fs.Stat` details
420
+ * of the given fd. If the `statCheck` function is provided, the`http2stream.respondWithFD()` method will perform an `fs.fstat()` call to
421
+ * collect details on the provided file descriptor.
422
+ *
423
+ * The `offset` and `length` options may be used to limit the response to a
424
+ * specific range subset. This can be used, for instance, to support HTTP Range
425
+ * requests.
426
+ *
427
+ * The file descriptor or `FileHandle` is not closed when the stream is closed,
428
+ * so it will need to be closed manually once it is no longer needed.
429
+ * Using the same file descriptor concurrently for multiple streams
430
+ * is not supported and may result in data loss. Re-using a file descriptor
431
+ * after a stream has finished is supported.
432
+ *
433
+ * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
434
+ * will be emitted immediately after queuing the last chunk of payload data to be
435
+ * sent. The `http2stream.sendTrailers()` method can then be used to sent trailing
436
+ * header fields to the peer.
437
+ *
438
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
439
+ * close when the final `DATA` frame is transmitted. User code _must_ call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
440
+ *
441
+ * ```js
442
+ * const http2 = require('http2');
443
+ * const fs = require('fs');
444
+ *
445
+ * const server = http2.createServer();
446
+ * server.on('stream', (stream) => {
447
+ * const fd = fs.openSync('/some/file', 'r');
448
+ *
449
+ * const stat = fs.fstatSync(fd);
450
+ * const headers = {
451
+ * 'content-length': stat.size,
452
+ * 'last-modified': stat.mtime.toUTCString(),
453
+ * 'content-type': 'text/plain; charset=utf-8'
454
+ * };
455
+ * stream.respondWithFD(fd, headers, { waitForTrailers: true });
456
+ * stream.on('wantTrailers', () => {
457
+ * stream.sendTrailers({ ABC: 'some value to send' });
458
+ * });
459
+ *
460
+ * stream.on('close', () => fs.closeSync(fd));
461
+ * });
462
+ * ```
463
+ * @since v8.4.0
464
+ * @param fd A readable file descriptor.
465
+ */
233
466
  respondWithFD(fd: number | fs.promises.FileHandle, headers?: OutgoingHttpHeaders, options?: ServerStreamFileResponseOptions): void;
467
+ /**
468
+ * Sends a regular file as the response. The `path` must specify a regular file
469
+ * or an `'error'` event will be emitted on the `Http2Stream` object.
470
+ *
471
+ * When used, the `Http2Stream` object's `Duplex` interface will be closed
472
+ * automatically.
473
+ *
474
+ * The optional `options.statCheck` function may be specified to give user code
475
+ * an opportunity to set additional content headers based on the `fs.Stat` details
476
+ * of the given file:
477
+ *
478
+ * If an error occurs while attempting to read the file data, the `Http2Stream`will be closed using an `RST_STREAM` frame using the standard `INTERNAL_ERROR`code. If the `onError` callback is
479
+ * defined, then it will be called. Otherwise
480
+ * the stream will be destroyed.
481
+ *
482
+ * Example using a file path:
483
+ *
484
+ * ```js
485
+ * const http2 = require('http2');
486
+ * const server = http2.createServer();
487
+ * server.on('stream', (stream) => {
488
+ * function statCheck(stat, headers) {
489
+ * headers['last-modified'] = stat.mtime.toUTCString();
490
+ * }
491
+ *
492
+ * function onError(err) {
493
+ * // stream.respond() can throw if the stream has been destroyed by
494
+ * // the other side.
495
+ * try {
496
+ * if (err.code === 'ENOENT') {
497
+ * stream.respond({ ':status': 404 });
498
+ * } else {
499
+ * stream.respond({ ':status': 500 });
500
+ * }
501
+ * } catch (err) {
502
+ * // Perform actual error handling.
503
+ * console.log(err);
504
+ * }
505
+ * stream.end();
506
+ * }
507
+ *
508
+ * stream.respondWithFile('/some/file',
509
+ * { 'content-type': 'text/plain; charset=utf-8' },
510
+ * { statCheck, onError });
511
+ * });
512
+ * ```
513
+ *
514
+ * The `options.statCheck` function may also be used to cancel the send operation
515
+ * by returning `false`. For instance, a conditional request may check the stat
516
+ * results to determine if the file has been modified to return an appropriate`304` response:
517
+ *
518
+ * ```js
519
+ * const http2 = require('http2');
520
+ * const server = http2.createServer();
521
+ * server.on('stream', (stream) => {
522
+ * function statCheck(stat, headers) {
523
+ * // Check the stat here...
524
+ * stream.respond({ ':status': 304 });
525
+ * return false; // Cancel the send operation
526
+ * }
527
+ * stream.respondWithFile('/some/file',
528
+ * { 'content-type': 'text/plain; charset=utf-8' },
529
+ * { statCheck });
530
+ * });
531
+ * ```
532
+ *
533
+ * The `content-length` header field will be automatically set.
534
+ *
535
+ * The `offset` and `length` options may be used to limit the response to a
536
+ * specific range subset. This can be used, for instance, to support HTTP Range
537
+ * requests.
538
+ *
539
+ * The `options.onError` function may also be used to handle all the errors
540
+ * that could happen before the delivery of the file is initiated. The
541
+ * default behavior is to destroy the stream.
542
+ *
543
+ * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
544
+ * will be emitted immediately after queuing the last chunk of payload data to be
545
+ * sent. The `http2stream.sendTrailers()` method can then be used to sent trailing
546
+ * header fields to the peer.
547
+ *
548
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
549
+ * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
550
+ *
551
+ * ```js
552
+ * const http2 = require('http2');
553
+ * const server = http2.createServer();
554
+ * server.on('stream', (stream) => {
555
+ * stream.respondWithFile('/some/file',
556
+ * { 'content-type': 'text/plain; charset=utf-8' },
557
+ * { waitForTrailers: true });
558
+ * stream.on('wantTrailers', () => {
559
+ * stream.sendTrailers({ ABC: 'some value to send' });
560
+ * });
561
+ * });
562
+ * ```
563
+ * @since v8.4.0
564
+ */
234
565
  respondWithFile(path: string, headers?: OutgoingHttpHeaders, options?: ServerStreamFileResponseOptionsWithError): void;
235
566
  }
236
-
237
567
  // Http2Session
238
-
239
568
  export interface Settings {
240
569
  headerTableSize?: number | undefined;
241
570
  enablePush?: boolean | undefined;
@@ -245,7 +574,6 @@ declare module 'http2' {
245
574
  maxHeaderListSize?: number | undefined;
246
575
  enableConnectProtocol?: boolean | undefined;
247
576
  }
248
-
249
577
  export interface ClientSessionRequestOptions {
250
578
  endStream?: boolean | undefined;
251
579
  exclusive?: boolean | undefined;
@@ -253,7 +581,6 @@ declare module 'http2' {
253
581
  weight?: number | undefined;
254
582
  waitForTrailers?: boolean | undefined;
255
583
  }
256
-
257
584
  export interface SessionState {
258
585
  effectiveLocalWindowSize?: number | undefined;
259
586
  effectiveRecvDataLength?: number | undefined;
@@ -265,170 +592,444 @@ declare module 'http2' {
265
592
  deflateDynamicTableSize?: number | undefined;
266
593
  inflateDynamicTableSize?: number | undefined;
267
594
  }
268
-
269
595
  export interface Http2Session extends EventEmitter {
596
+ /**
597
+ * Value will be `undefined` if the `Http2Session` is not yet connected to a
598
+ * socket, `h2c` if the `Http2Session` is not connected to a `TLSSocket`, or
599
+ * will return the value of the connected `TLSSocket`'s own `alpnProtocol`property.
600
+ * @since v9.4.0
601
+ */
270
602
  readonly alpnProtocol?: string | undefined;
603
+ /**
604
+ * Will be `true` if this `Http2Session` instance has been closed, otherwise`false`.
605
+ * @since v9.4.0
606
+ */
271
607
  readonly closed: boolean;
608
+ /**
609
+ * Will be `true` if this `Http2Session` instance is still connecting, will be set
610
+ * to `false` before emitting `connect` event and/or calling the `http2.connect`callback.
611
+ * @since v10.0.0
612
+ */
272
613
  readonly connecting: boolean;
614
+ /**
615
+ * Will be `true` if this `Http2Session` instance has been destroyed and must no
616
+ * longer be used, otherwise `false`.
617
+ * @since v8.4.0
618
+ */
273
619
  readonly destroyed: boolean;
620
+ /**
621
+ * Value is `undefined` if the `Http2Session` session socket has not yet been
622
+ * connected, `true` if the `Http2Session` is connected with a `TLSSocket`,
623
+ * and `false` if the `Http2Session` is connected to any other kind of socket
624
+ * or stream.
625
+ * @since v9.4.0
626
+ */
274
627
  readonly encrypted?: boolean | undefined;
628
+ /**
629
+ * A prototype-less object describing the current local settings of this`Http2Session`. The local settings are local to _this_`Http2Session` instance.
630
+ * @since v8.4.0
631
+ */
275
632
  readonly localSettings: Settings;
633
+ /**
634
+ * If the `Http2Session` is connected to a `TLSSocket`, the `originSet` property
635
+ * will return an `Array` of origins for which the `Http2Session` may be
636
+ * considered authoritative.
637
+ *
638
+ * The `originSet` property is only available when using a secure TLS connection.
639
+ * @since v9.4.0
640
+ */
276
641
  readonly originSet?: string[] | undefined;
642
+ /**
643
+ * Indicates whether the `Http2Session` is currently waiting for acknowledgment of
644
+ * a sent `SETTINGS` frame. Will be `true` after calling the`http2session.settings()` method. Will be `false` once all sent `SETTINGS`frames have been acknowledged.
645
+ * @since v8.4.0
646
+ */
277
647
  readonly pendingSettingsAck: boolean;
648
+ /**
649
+ * A prototype-less object describing the current remote settings of this`Http2Session`. The remote settings are set by the _connected_ HTTP/2 peer.
650
+ * @since v8.4.0
651
+ */
278
652
  readonly remoteSettings: Settings;
653
+ /**
654
+ * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
655
+ * limits available methods to ones safe to use with HTTP/2.
656
+ *
657
+ * `destroy`, `emit`, `end`, `pause`, `read`, `resume`, and `write` will throw
658
+ * an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for more information.
659
+ *
660
+ * `setTimeout` method will be called on this `Http2Session`.
661
+ *
662
+ * All other interactions will be routed directly to the socket.
663
+ * @since v8.4.0
664
+ */
279
665
  readonly socket: net.Socket | tls.TLSSocket;
666
+ /**
667
+ * Provides miscellaneous information about the current state of the`Http2Session`.
668
+ *
669
+ * An object describing the current status of this `Http2Session`.
670
+ * @since v8.4.0
671
+ */
280
672
  readonly state: SessionState;
673
+ /**
674
+ * The `http2session.type` will be equal to`http2.constants.NGHTTP2_SESSION_SERVER` if this `Http2Session` instance is a
675
+ * server, and `http2.constants.NGHTTP2_SESSION_CLIENT` if the instance is a
676
+ * client.
677
+ * @since v8.4.0
678
+ */
281
679
  readonly type: number;
282
-
680
+ /**
681
+ * Gracefully closes the `Http2Session`, allowing any existing streams to
682
+ * complete on their own and preventing new `Http2Stream` instances from being
683
+ * created. Once closed, `http2session.destroy()`_might_ be called if there
684
+ * are no open `Http2Stream` instances.
685
+ *
686
+ * If specified, the `callback` function is registered as a handler for the`'close'` event.
687
+ * @since v9.4.0
688
+ */
283
689
  close(callback?: () => void): void;
690
+ /**
691
+ * Immediately terminates the `Http2Session` and the associated `net.Socket` or`tls.TLSSocket`.
692
+ *
693
+ * Once destroyed, the `Http2Session` will emit the `'close'` event. If `error`is not undefined, an `'error'` event will be emitted immediately before the`'close'` event.
694
+ *
695
+ * If there are any remaining open `Http2Streams` associated with the`Http2Session`, those will also be destroyed.
696
+ * @since v8.4.0
697
+ * @param error An `Error` object if the `Http2Session` is being destroyed due to an error.
698
+ * @param code The HTTP/2 error code to send in the final `GOAWAY` frame. If unspecified, and `error` is not undefined, the default is `INTERNAL_ERROR`, otherwise defaults to `NO_ERROR`.
699
+ */
284
700
  destroy(error?: Error, code?: number): void;
701
+ /**
702
+ * Transmits a `GOAWAY` frame to the connected peer _without_ shutting down the`Http2Session`.
703
+ * @since v9.4.0
704
+ * @param code An HTTP/2 error code
705
+ * @param lastStreamID The numeric ID of the last processed `Http2Stream`
706
+ * @param opaqueData A `TypedArray` or `DataView` instance containing additional data to be carried within the `GOAWAY` frame.
707
+ */
285
708
  goaway(code?: number, lastStreamID?: number, opaqueData?: NodeJS.ArrayBufferView): void;
709
+ /**
710
+ * Sends a `PING` frame to the connected HTTP/2 peer. A `callback` function must
711
+ * be provided. The method will return `true` if the `PING` was sent, `false`otherwise.
712
+ *
713
+ * The maximum number of outstanding (unacknowledged) pings is determined by the`maxOutstandingPings` configuration option. The default maximum is 10.
714
+ *
715
+ * If provided, the `payload` must be a `Buffer`, `TypedArray`, or `DataView`containing 8 bytes of data that will be transmitted with the `PING` and
716
+ * returned with the ping acknowledgment.
717
+ *
718
+ * The callback will be invoked with three arguments: an error argument that will
719
+ * be `null` if the `PING` was successfully acknowledged, a `duration` argument
720
+ * that reports the number of milliseconds elapsed since the ping was sent and the
721
+ * acknowledgment was received, and a `Buffer` containing the 8-byte `PING`payload.
722
+ *
723
+ * ```js
724
+ * session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
725
+ * if (!err) {
726
+ * console.log(`Ping acknowledged in ${duration} milliseconds`);
727
+ * console.log(`With payload '${payload.toString()}'`);
728
+ * }
729
+ * });
730
+ * ```
731
+ *
732
+ * If the `payload` argument is not specified, the default payload will be the
733
+ * 64-bit timestamp (little endian) marking the start of the `PING` duration.
734
+ * @since v8.9.3
735
+ * @param payload Optional ping payload.
736
+ */
286
737
  ping(callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean;
287
738
  ping(payload: NodeJS.ArrayBufferView, callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean;
739
+ /**
740
+ * Calls `ref()` on this `Http2Session`instance's underlying `net.Socket`.
741
+ * @since v9.4.0
742
+ */
288
743
  ref(): void;
744
+ /**
745
+ * Sets the local endpoint's window size.
746
+ * The `windowSize` is the total window size to set, not
747
+ * the delta.
748
+ *
749
+ * ```js
750
+ * const http2 = require('http2');
751
+ *
752
+ * const server = http2.createServer();
753
+ * const expectedWindowSize = 2 ** 20;
754
+ * server.on('connect', (session) => {
755
+ *
756
+ * // Set local window size to be 2 ** 20
757
+ * session.setLocalWindowSize(expectedWindowSize);
758
+ * });
759
+ * ```
760
+ * @since v15.3.0
761
+ */
289
762
  setLocalWindowSize(windowSize: number): void;
763
+ /**
764
+ * Used to set a callback function that is called when there is no activity on
765
+ * the `Http2Session` after `msecs` milliseconds. The given `callback` is
766
+ * registered as a listener on the `'timeout'` event.
767
+ * @since v8.4.0
768
+ */
290
769
  setTimeout(msecs: number, callback?: () => void): void;
770
+ /**
771
+ * Updates the current local settings for this `Http2Session` and sends a new`SETTINGS` frame to the connected HTTP/2 peer.
772
+ *
773
+ * Once called, the `http2session.pendingSettingsAck` property will be `true`while the session is waiting for the remote peer to acknowledge the new
774
+ * settings.
775
+ *
776
+ * The new settings will not become effective until the `SETTINGS` acknowledgment
777
+ * is received and the `'localSettings'` event is emitted. It is possible to send
778
+ * multiple `SETTINGS` frames while acknowledgment is still pending.
779
+ * @since v8.4.0
780
+ * @param callback Callback that is called once the session is connected or right away if the session is already connected.
781
+ */
291
782
  settings(settings: Settings): void;
783
+ /**
784
+ * Calls `unref()` on this `Http2Session`instance's underlying `net.Socket`.
785
+ * @since v9.4.0
786
+ */
292
787
  unref(): void;
293
-
294
- addListener(event: "close", listener: () => void): this;
295
- addListener(event: "error", listener: (err: Error) => void): this;
296
- addListener(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
297
- addListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
298
- addListener(event: "localSettings", listener: (settings: Settings) => void): this;
299
- addListener(event: "ping", listener: () => void): this;
300
- addListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
301
- addListener(event: "timeout", listener: () => void): this;
788
+ addListener(event: 'close', listener: () => void): this;
789
+ addListener(event: 'error', listener: (err: Error) => void): this;
790
+ addListener(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
791
+ addListener(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
792
+ addListener(event: 'localSettings', listener: (settings: Settings) => void): this;
793
+ addListener(event: 'ping', listener: () => void): this;
794
+ addListener(event: 'remoteSettings', listener: (settings: Settings) => void): this;
795
+ addListener(event: 'timeout', listener: () => void): this;
302
796
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
303
-
304
- emit(event: "close"): boolean;
305
- emit(event: "error", err: Error): boolean;
306
- emit(event: "frameError", frameType: number, errorCode: number, streamID: number): boolean;
307
- emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData: Buffer): boolean;
308
- emit(event: "localSettings", settings: Settings): boolean;
309
- emit(event: "ping"): boolean;
310
- emit(event: "remoteSettings", settings: Settings): boolean;
311
- emit(event: "timeout"): boolean;
797
+ emit(event: 'close'): boolean;
798
+ emit(event: 'error', err: Error): boolean;
799
+ emit(event: 'frameError', frameType: number, errorCode: number, streamID: number): boolean;
800
+ emit(event: 'goaway', errorCode: number, lastStreamID: number, opaqueData: Buffer): boolean;
801
+ emit(event: 'localSettings', settings: Settings): boolean;
802
+ emit(event: 'ping'): boolean;
803
+ emit(event: 'remoteSettings', settings: Settings): boolean;
804
+ emit(event: 'timeout'): boolean;
312
805
  emit(event: string | symbol, ...args: any[]): boolean;
313
-
314
- on(event: "close", listener: () => void): this;
315
- on(event: "error", listener: (err: Error) => void): this;
316
- on(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
317
- on(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
318
- on(event: "localSettings", listener: (settings: Settings) => void): this;
319
- on(event: "ping", listener: () => void): this;
320
- on(event: "remoteSettings", listener: (settings: Settings) => void): this;
321
- on(event: "timeout", listener: () => void): this;
806
+ on(event: 'close', listener: () => void): this;
807
+ on(event: 'error', listener: (err: Error) => void): this;
808
+ on(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
809
+ on(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
810
+ on(event: 'localSettings', listener: (settings: Settings) => void): this;
811
+ on(event: 'ping', listener: () => void): this;
812
+ on(event: 'remoteSettings', listener: (settings: Settings) => void): this;
813
+ on(event: 'timeout', listener: () => void): this;
322
814
  on(event: string | symbol, listener: (...args: any[]) => void): this;
323
-
324
- once(event: "close", listener: () => void): this;
325
- once(event: "error", listener: (err: Error) => void): this;
326
- once(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
327
- once(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
328
- once(event: "localSettings", listener: (settings: Settings) => void): this;
329
- once(event: "ping", listener: () => void): this;
330
- once(event: "remoteSettings", listener: (settings: Settings) => void): this;
331
- once(event: "timeout", listener: () => void): this;
815
+ once(event: 'close', listener: () => void): this;
816
+ once(event: 'error', listener: (err: Error) => void): this;
817
+ once(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
818
+ once(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
819
+ once(event: 'localSettings', listener: (settings: Settings) => void): this;
820
+ once(event: 'ping', listener: () => void): this;
821
+ once(event: 'remoteSettings', listener: (settings: Settings) => void): this;
822
+ once(event: 'timeout', listener: () => void): this;
332
823
  once(event: string | symbol, listener: (...args: any[]) => void): this;
333
-
334
- prependListener(event: "close", listener: () => void): this;
335
- prependListener(event: "error", listener: (err: Error) => void): this;
336
- prependListener(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
337
- prependListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
338
- prependListener(event: "localSettings", listener: (settings: Settings) => void): this;
339
- prependListener(event: "ping", listener: () => void): this;
340
- prependListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
341
- prependListener(event: "timeout", listener: () => void): this;
824
+ prependListener(event: 'close', listener: () => void): this;
825
+ prependListener(event: 'error', listener: (err: Error) => void): this;
826
+ prependListener(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
827
+ prependListener(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
828
+ prependListener(event: 'localSettings', listener: (settings: Settings) => void): this;
829
+ prependListener(event: 'ping', listener: () => void): this;
830
+ prependListener(event: 'remoteSettings', listener: (settings: Settings) => void): this;
831
+ prependListener(event: 'timeout', listener: () => void): this;
342
832
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
343
-
344
- prependOnceListener(event: "close", listener: () => void): this;
345
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
346
- prependOnceListener(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
347
- prependOnceListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
348
- prependOnceListener(event: "localSettings", listener: (settings: Settings) => void): this;
349
- prependOnceListener(event: "ping", listener: () => void): this;
350
- prependOnceListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
351
- prependOnceListener(event: "timeout", listener: () => void): this;
833
+ prependOnceListener(event: 'close', listener: () => void): this;
834
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
835
+ prependOnceListener(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
836
+ prependOnceListener(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
837
+ prependOnceListener(event: 'localSettings', listener: (settings: Settings) => void): this;
838
+ prependOnceListener(event: 'ping', listener: () => void): this;
839
+ prependOnceListener(event: 'remoteSettings', listener: (settings: Settings) => void): this;
840
+ prependOnceListener(event: 'timeout', listener: () => void): this;
352
841
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
353
842
  }
354
-
355
843
  export interface ClientHttp2Session extends Http2Session {
844
+ /**
845
+ * For HTTP/2 Client `Http2Session` instances only, the `http2session.request()`creates and returns an `Http2Stream` instance that can be used to send an
846
+ * HTTP/2 request to the connected server.
847
+ *
848
+ * This method is only available if `http2session.type` is equal to`http2.constants.NGHTTP2_SESSION_CLIENT`.
849
+ *
850
+ * ```js
851
+ * const http2 = require('http2');
852
+ * const clientSession = http2.connect('https://localhost:1234');
853
+ * const {
854
+ * HTTP2_HEADER_PATH,
855
+ * HTTP2_HEADER_STATUS
856
+ * } = http2.constants;
857
+ *
858
+ * const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
859
+ * req.on('response', (headers) => {
860
+ * console.log(headers[HTTP2_HEADER_STATUS]);
861
+ * req.on('data', (chunk) => { // .. });
862
+ * req.on('end', () => { // .. });
863
+ * });
864
+ * ```
865
+ *
866
+ * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
867
+ * is emitted immediately after queuing the last chunk of payload data to be sent.
868
+ * The `http2stream.sendTrailers()` method can then be called to send trailing
869
+ * headers to the peer.
870
+ *
871
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
872
+ * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
873
+ *
874
+ * When `options.signal` is set with an `AbortSignal` and then `abort` on the
875
+ * corresponding `AbortController` is called, the request will emit an `'error'`event with an `AbortError` error.
876
+ *
877
+ * The `:method` and `:path` pseudo-headers are not specified within `headers`,
878
+ * they respectively default to:
879
+ *
880
+ * * `:method` \= `'GET'`
881
+ * * `:path` \= `/`
882
+ * @since v8.4.0
883
+ */
356
884
  request(headers?: OutgoingHttpHeaders, options?: ClientSessionRequestOptions): ClientHttp2Stream;
357
-
358
- addListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
359
- addListener(event: "origin", listener: (origins: string[]) => void): this;
360
- addListener(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
361
- addListener(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
885
+ addListener(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
886
+ addListener(event: 'origin', listener: (origins: string[]) => void): this;
887
+ addListener(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
888
+ addListener(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
362
889
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
363
-
364
- emit(event: "altsvc", alt: string, origin: string, stream: number): boolean;
365
- emit(event: "origin", origins: ReadonlyArray<string>): boolean;
366
- emit(event: "connect", session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
367
- emit(event: "stream", stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
890
+ emit(event: 'altsvc', alt: string, origin: string, stream: number): boolean;
891
+ emit(event: 'origin', origins: ReadonlyArray<string>): boolean;
892
+ emit(event: 'connect', session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
893
+ emit(event: 'stream', stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
368
894
  emit(event: string | symbol, ...args: any[]): boolean;
369
-
370
- on(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
371
- on(event: "origin", listener: (origins: string[]) => void): this;
372
- on(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
373
- on(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
895
+ on(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
896
+ on(event: 'origin', listener: (origins: string[]) => void): this;
897
+ on(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
898
+ on(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
374
899
  on(event: string | symbol, listener: (...args: any[]) => void): this;
375
-
376
- once(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
377
- once(event: "origin", listener: (origins: string[]) => void): this;
378
- once(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
379
- once(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
900
+ once(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
901
+ once(event: 'origin', listener: (origins: string[]) => void): this;
902
+ once(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
903
+ once(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
380
904
  once(event: string | symbol, listener: (...args: any[]) => void): this;
381
-
382
- prependListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
383
- prependListener(event: "origin", listener: (origins: string[]) => void): this;
384
- prependListener(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
385
- prependListener(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
905
+ prependListener(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
906
+ prependListener(event: 'origin', listener: (origins: string[]) => void): this;
907
+ prependListener(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
908
+ prependListener(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
386
909
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
387
-
388
- prependOnceListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
389
- prependOnceListener(event: "origin", listener: (origins: string[]) => void): this;
390
- prependOnceListener(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
391
- prependOnceListener(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
910
+ prependOnceListener(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
911
+ prependOnceListener(event: 'origin', listener: (origins: string[]) => void): this;
912
+ prependOnceListener(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
913
+ prependOnceListener(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
392
914
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
393
915
  }
394
-
395
916
  export interface AlternativeServiceOptions {
396
917
  origin: number | string | url.URL;
397
918
  }
398
-
399
919
  export interface ServerHttp2Session extends Http2Session {
400
920
  readonly server: Http2Server | Http2SecureServer;
401
-
921
+ /**
922
+ * Submits an `ALTSVC` frame (as defined by [RFC 7838](https://tools.ietf.org/html/rfc7838)) to the connected client.
923
+ *
924
+ * ```js
925
+ * const http2 = require('http2');
926
+ *
927
+ * const server = http2.createServer();
928
+ * server.on('session', (session) => {
929
+ * // Set altsvc for origin https://example.org:80
930
+ * session.altsvc('h2=":8000"', 'https://example.org:80');
931
+ * });
932
+ *
933
+ * server.on('stream', (stream) => {
934
+ * // Set altsvc for a specific stream
935
+ * stream.session.altsvc('h2=":8000"', stream.id);
936
+ * });
937
+ * ```
938
+ *
939
+ * Sending an `ALTSVC` frame with a specific stream ID indicates that the alternate
940
+ * service is associated with the origin of the given `Http2Stream`.
941
+ *
942
+ * The `alt` and origin string _must_ contain only ASCII bytes and are
943
+ * strictly interpreted as a sequence of ASCII bytes. The special value `'clear'`may be passed to clear any previously set alternative service for a given
944
+ * domain.
945
+ *
946
+ * When a string is passed for the `originOrStream` argument, it will be parsed as
947
+ * a URL and the origin will be derived. For instance, the origin for the
948
+ * HTTP URL `'https://example.org/foo/bar'` is the ASCII string`'https://example.org'`. An error will be thrown if either the given string
949
+ * cannot be parsed as a URL or if a valid origin cannot be derived.
950
+ *
951
+ * A `URL` object, or any object with an `origin` property, may be passed as`originOrStream`, in which case the value of the `origin` property will be
952
+ * used. The value of the `origin` property _must_ be a properly serialized
953
+ * ASCII origin.
954
+ * @since v9.4.0
955
+ * @param alt A description of the alternative service configuration as defined by `RFC 7838`.
956
+ * @param originOrStream Either a URL string specifying the origin (or an `Object` with an `origin` property) or the numeric identifier of an active `Http2Stream` as given by the
957
+ * `http2stream.id` property.
958
+ */
402
959
  altsvc(alt: string, originOrStream: number | string | url.URL | AlternativeServiceOptions): void;
403
- origin(...args: Array<string | url.URL | { origin: string }>): void;
404
-
405
- addListener(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
406
- addListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
960
+ /**
961
+ * Submits an `ORIGIN` frame (as defined by [RFC 8336](https://tools.ietf.org/html/rfc8336)) to the connected client
962
+ * to advertise the set of origins for which the server is capable of providing
963
+ * authoritative responses.
964
+ *
965
+ * ```js
966
+ * const http2 = require('http2');
967
+ * const options = getSecureOptionsSomehow();
968
+ * const server = http2.createSecureServer(options);
969
+ * server.on('stream', (stream) => {
970
+ * stream.respond();
971
+ * stream.end('ok');
972
+ * });
973
+ * server.on('session', (session) => {
974
+ * session.origin('https://example.com', 'https://example.org');
975
+ * });
976
+ * ```
977
+ *
978
+ * When a string is passed as an `origin`, it will be parsed as a URL and the
979
+ * origin will be derived. For instance, the origin for the HTTP URL`'https://example.org/foo/bar'` is the ASCII string`'https://example.org'`. An error will be thrown if either the given
980
+ * string
981
+ * cannot be parsed as a URL or if a valid origin cannot be derived.
982
+ *
983
+ * A `URL` object, or any object with an `origin` property, may be passed as
984
+ * an `origin`, in which case the value of the `origin` property will be
985
+ * used. The value of the `origin` property _must_ be a properly serialized
986
+ * ASCII origin.
987
+ *
988
+ * Alternatively, the `origins` option may be used when creating a new HTTP/2
989
+ * server using the `http2.createSecureServer()` method:
990
+ *
991
+ * ```js
992
+ * const http2 = require('http2');
993
+ * const options = getSecureOptionsSomehow();
994
+ * options.origins = ['https://example.com', 'https://example.org'];
995
+ * const server = http2.createSecureServer(options);
996
+ * server.on('stream', (stream) => {
997
+ * stream.respond();
998
+ * stream.end('ok');
999
+ * });
1000
+ * ```
1001
+ * @since v10.12.0
1002
+ * @param origins One or more URL Strings passed as separate arguments.
1003
+ */
1004
+ origin(
1005
+ ...args: Array<
1006
+ | string
1007
+ | url.URL
1008
+ | {
1009
+ origin: string;
1010
+ }
1011
+ >
1012
+ ): void;
1013
+ addListener(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1014
+ addListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
407
1015
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
408
-
409
- emit(event: "connect", session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
410
- emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1016
+ emit(event: 'connect', session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
1017
+ emit(event: 'stream', stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
411
1018
  emit(event: string | symbol, ...args: any[]): boolean;
412
-
413
- on(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
414
- on(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1019
+ on(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1020
+ on(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
415
1021
  on(event: string | symbol, listener: (...args: any[]) => void): this;
416
-
417
- once(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
418
- once(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1022
+ once(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1023
+ once(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
419
1024
  once(event: string | symbol, listener: (...args: any[]) => void): this;
420
-
421
- prependListener(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
422
- prependListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1025
+ prependListener(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1026
+ prependListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
423
1027
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
424
-
425
- prependOnceListener(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
426
- prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1028
+ prependOnceListener(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1029
+ prependOnceListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
427
1030
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
428
1031
  }
429
-
430
1032
  // Http2Server
431
-
432
1033
  export interface SessionOptions {
433
1034
  maxDeflateDynamicTableSize?: number | undefined;
434
1035
  maxSessionMemory?: number | undefined;
@@ -445,34 +1046,27 @@ declare module 'http2' {
445
1046
  * @default 100000
446
1047
  */
447
1048
  unknownProtocolTimeout?: number | undefined;
448
-
449
1049
  selectPadding?(frameLen: number, maxFrameLen: number): number;
450
1050
  createConnection?(authority: url.URL, option: SessionOptions): stream.Duplex;
451
1051
  }
452
-
453
1052
  export interface ClientSessionOptions extends SessionOptions {
454
1053
  maxReservedRemoteStreams?: number | undefined;
455
1054
  createConnection?: ((authority: url.URL, option: SessionOptions) => stream.Duplex) | undefined;
456
1055
  protocol?: 'http:' | 'https:' | undefined;
457
1056
  }
458
-
459
1057
  export interface ServerSessionOptions extends SessionOptions {
460
1058
  Http1IncomingMessage?: typeof IncomingMessage | undefined;
461
1059
  Http1ServerResponse?: typeof ServerResponse | undefined;
462
1060
  Http2ServerRequest?: typeof Http2ServerRequest | undefined;
463
1061
  Http2ServerResponse?: typeof Http2ServerResponse | undefined;
464
1062
  }
465
-
466
- export interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions { }
467
- export interface SecureServerSessionOptions extends ServerSessionOptions, tls.TlsOptions { }
468
-
469
- export interface ServerOptions extends ServerSessionOptions { }
470
-
1063
+ export interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions {}
1064
+ export interface SecureServerSessionOptions extends ServerSessionOptions, tls.TlsOptions {}
1065
+ export interface ServerOptions extends ServerSessionOptions {}
471
1066
  export interface SecureServerOptions extends SecureServerSessionOptions {
472
1067
  allowHTTP1?: boolean | undefined;
473
1068
  origins?: string[] | undefined;
474
1069
  }
475
-
476
1070
  interface HTTP2ServerCommon {
477
1071
  setTimeout(msec?: number, callback?: () => void): this;
478
1072
  /**
@@ -481,265 +1075,639 @@ declare module 'http2' {
481
1075
  */
482
1076
  updateSettings(settings: Settings): void;
483
1077
  }
484
-
485
1078
  export interface Http2Server extends net.Server, HTTP2ServerCommon {
486
- addListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
487
- addListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
488
- addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
489
- addListener(event: "sessionError", listener: (err: Error) => void): this;
490
- addListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
491
- addListener(event: "timeout", listener: () => void): this;
1079
+ addListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1080
+ addListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1081
+ addListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1082
+ addListener(event: 'sessionError', listener: (err: Error) => void): this;
1083
+ addListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1084
+ addListener(event: 'timeout', listener: () => void): this;
492
1085
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
493
-
494
- emit(event: "checkContinue", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
495
- emit(event: "request", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
496
- emit(event: "session", session: ServerHttp2Session): boolean;
497
- emit(event: "sessionError", err: Error): boolean;
498
- emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
499
- emit(event: "timeout"): boolean;
1086
+ emit(event: 'checkContinue', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1087
+ emit(event: 'request', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1088
+ emit(event: 'session', session: ServerHttp2Session): boolean;
1089
+ emit(event: 'sessionError', err: Error): boolean;
1090
+ emit(event: 'stream', stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1091
+ emit(event: 'timeout'): boolean;
500
1092
  emit(event: string | symbol, ...args: any[]): boolean;
501
-
502
- on(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
503
- on(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
504
- on(event: "session", listener: (session: ServerHttp2Session) => void): this;
505
- on(event: "sessionError", listener: (err: Error) => void): this;
506
- on(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
507
- on(event: "timeout", listener: () => void): this;
1093
+ on(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1094
+ on(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1095
+ on(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1096
+ on(event: 'sessionError', listener: (err: Error) => void): this;
1097
+ on(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1098
+ on(event: 'timeout', listener: () => void): this;
508
1099
  on(event: string | symbol, listener: (...args: any[]) => void): this;
509
-
510
- once(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
511
- once(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
512
- once(event: "session", listener: (session: ServerHttp2Session) => void): this;
513
- once(event: "sessionError", listener: (err: Error) => void): this;
514
- once(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
515
- once(event: "timeout", listener: () => void): this;
1100
+ once(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1101
+ once(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1102
+ once(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1103
+ once(event: 'sessionError', listener: (err: Error) => void): this;
1104
+ once(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1105
+ once(event: 'timeout', listener: () => void): this;
516
1106
  once(event: string | symbol, listener: (...args: any[]) => void): this;
517
-
518
- prependListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
519
- prependListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
520
- prependListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
521
- prependListener(event: "sessionError", listener: (err: Error) => void): this;
522
- prependListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
523
- prependListener(event: "timeout", listener: () => void): this;
1107
+ prependListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1108
+ prependListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1109
+ prependListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1110
+ prependListener(event: 'sessionError', listener: (err: Error) => void): this;
1111
+ prependListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1112
+ prependListener(event: 'timeout', listener: () => void): this;
524
1113
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
525
-
526
- prependOnceListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
527
- prependOnceListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
528
- prependOnceListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
529
- prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
530
- prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
531
- prependOnceListener(event: "timeout", listener: () => void): this;
1114
+ prependOnceListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1115
+ prependOnceListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1116
+ prependOnceListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1117
+ prependOnceListener(event: 'sessionError', listener: (err: Error) => void): this;
1118
+ prependOnceListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1119
+ prependOnceListener(event: 'timeout', listener: () => void): this;
532
1120
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
533
1121
  }
534
-
535
1122
  export interface Http2SecureServer extends tls.Server, HTTP2ServerCommon {
536
- addListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
537
- addListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
538
- addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
539
- addListener(event: "sessionError", listener: (err: Error) => void): this;
540
- addListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
541
- addListener(event: "timeout", listener: () => void): this;
542
- addListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
1123
+ addListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1124
+ addListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1125
+ addListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1126
+ addListener(event: 'sessionError', listener: (err: Error) => void): this;
1127
+ addListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1128
+ addListener(event: 'timeout', listener: () => void): this;
1129
+ addListener(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
543
1130
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
544
-
545
- emit(event: "checkContinue", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
546
- emit(event: "request", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
547
- emit(event: "session", session: ServerHttp2Session): boolean;
548
- emit(event: "sessionError", err: Error): boolean;
549
- emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
550
- emit(event: "timeout"): boolean;
551
- emit(event: "unknownProtocol", socket: tls.TLSSocket): boolean;
1131
+ emit(event: 'checkContinue', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1132
+ emit(event: 'request', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1133
+ emit(event: 'session', session: ServerHttp2Session): boolean;
1134
+ emit(event: 'sessionError', err: Error): boolean;
1135
+ emit(event: 'stream', stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1136
+ emit(event: 'timeout'): boolean;
1137
+ emit(event: 'unknownProtocol', socket: tls.TLSSocket): boolean;
552
1138
  emit(event: string | symbol, ...args: any[]): boolean;
553
-
554
- on(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
555
- on(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
556
- on(event: "session", listener: (session: ServerHttp2Session) => void): this;
557
- on(event: "sessionError", listener: (err: Error) => void): this;
558
- on(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
559
- on(event: "timeout", listener: () => void): this;
560
- on(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
1139
+ on(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1140
+ on(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1141
+ on(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1142
+ on(event: 'sessionError', listener: (err: Error) => void): this;
1143
+ on(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1144
+ on(event: 'timeout', listener: () => void): this;
1145
+ on(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
561
1146
  on(event: string | symbol, listener: (...args: any[]) => void): this;
562
-
563
- once(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
564
- once(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
565
- once(event: "session", listener: (session: ServerHttp2Session) => void): this;
566
- once(event: "sessionError", listener: (err: Error) => void): this;
567
- once(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
568
- once(event: "timeout", listener: () => void): this;
569
- once(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
1147
+ once(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1148
+ once(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1149
+ once(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1150
+ once(event: 'sessionError', listener: (err: Error) => void): this;
1151
+ once(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1152
+ once(event: 'timeout', listener: () => void): this;
1153
+ once(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
570
1154
  once(event: string | symbol, listener: (...args: any[]) => void): this;
571
-
572
- prependListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
573
- prependListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
574
- prependListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
575
- prependListener(event: "sessionError", listener: (err: Error) => void): this;
576
- prependListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
577
- prependListener(event: "timeout", listener: () => void): this;
578
- prependListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
1155
+ prependListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1156
+ prependListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1157
+ prependListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1158
+ prependListener(event: 'sessionError', listener: (err: Error) => void): this;
1159
+ prependListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1160
+ prependListener(event: 'timeout', listener: () => void): this;
1161
+ prependListener(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
579
1162
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
580
-
581
- prependOnceListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
582
- prependOnceListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
583
- prependOnceListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
584
- prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
585
- prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
586
- prependOnceListener(event: "timeout", listener: () => void): this;
587
- prependOnceListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
1163
+ prependOnceListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1164
+ prependOnceListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1165
+ prependOnceListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1166
+ prependOnceListener(event: 'sessionError', listener: (err: Error) => void): this;
1167
+ prependOnceListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1168
+ prependOnceListener(event: 'timeout', listener: () => void): this;
1169
+ prependOnceListener(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
588
1170
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
589
1171
  }
590
-
1172
+ /**
1173
+ * * Extends: `<stream.Readable>`
1174
+ *
1175
+ * A `Http2ServerRequest` object is created by {@link Server} or {@link SecureServer} and passed as the first argument to the `'request'` event. It may be used to access a request status,
1176
+ * headers, and
1177
+ * data.
1178
+ * @since v8.4.0
1179
+ */
591
1180
  export class Http2ServerRequest extends stream.Readable {
592
1181
  constructor(stream: ServerHttp2Stream, headers: IncomingHttpHeaders, options: stream.ReadableOptions, rawHeaders: ReadonlyArray<string>);
593
-
1182
+ /**
1183
+ * The `request.aborted` property will be `true` if the request has
1184
+ * been aborted.
1185
+ * @since v10.1.0
1186
+ */
594
1187
  readonly aborted: boolean;
1188
+ /**
1189
+ * The request authority pseudo header field. Because HTTP/2 allows requests
1190
+ * to set either `:authority` or `host`, this value is derived from`req.headers[':authority']` if present. Otherwise, it is derived from`req.headers['host']`.
1191
+ * @since v8.4.0
1192
+ */
595
1193
  readonly authority: string;
1194
+ /**
1195
+ * See `request.socket`.
1196
+ * @since v8.4.0
1197
+ * @deprecated Since v13.0.0 - Deprecated. Use `socket`.
1198
+ */
596
1199
  readonly connection: net.Socket | tls.TLSSocket;
1200
+ /**
1201
+ * The `request.complete` property will be `true` if the request has
1202
+ * been completed, aborted, or destroyed.
1203
+ * @since v12.10.0
1204
+ */
597
1205
  readonly complete: boolean;
1206
+ /**
1207
+ * The request/response headers object.
1208
+ *
1209
+ * Key-value pairs of header names and values. Header names are lower-cased.
1210
+ *
1211
+ * ```js
1212
+ * // Prints something like:
1213
+ * //
1214
+ * // { 'user-agent': 'curl/7.22.0',
1215
+ * // host: '127.0.0.1:8000',
1216
+ * // accept: '*' }
1217
+ * console.log(request.headers);
1218
+ * ```
1219
+ *
1220
+ * See `HTTP/2 Headers Object`.
1221
+ *
1222
+ * In HTTP/2, the request path, host name, protocol, and method are represented as
1223
+ * special headers prefixed with the `:` character (e.g. `':path'`). These special
1224
+ * headers will be included in the `request.headers` object. Care must be taken not
1225
+ * to inadvertently modify these special headers or errors may occur. For instance,
1226
+ * removing all headers from the request will cause errors to occur:
1227
+ *
1228
+ * ```js
1229
+ * removeAllHeaders(request.headers);
1230
+ * assert(request.url); // Fails because the :path header has been removed
1231
+ * ```
1232
+ * @since v8.4.0
1233
+ */
598
1234
  readonly headers: IncomingHttpHeaders;
1235
+ /**
1236
+ * In case of server request, the HTTP version sent by the client. In the case of
1237
+ * client response, the HTTP version of the connected-to server. Returns`'2.0'`.
1238
+ *
1239
+ * Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
1240
+ * @since v8.4.0
1241
+ */
599
1242
  readonly httpVersion: string;
600
1243
  readonly httpVersionMinor: number;
601
1244
  readonly httpVersionMajor: number;
1245
+ /**
1246
+ * The request method as a string. Read-only. Examples: `'GET'`, `'DELETE'`.
1247
+ * @since v8.4.0
1248
+ */
602
1249
  readonly method: string;
1250
+ /**
1251
+ * The raw request/response headers list exactly as they were received.
1252
+ *
1253
+ * The keys and values are in the same list. It is _not_ a
1254
+ * list of tuples. So, the even-numbered offsets are key values, and the
1255
+ * odd-numbered offsets are the associated values.
1256
+ *
1257
+ * Header names are not lowercased, and duplicates are not merged.
1258
+ *
1259
+ * ```js
1260
+ * // Prints something like:
1261
+ * //
1262
+ * // [ 'user-agent',
1263
+ * // 'this is invalid because there can be only one',
1264
+ * // 'User-Agent',
1265
+ * // 'curl/7.22.0',
1266
+ * // 'Host',
1267
+ * // '127.0.0.1:8000',
1268
+ * // 'ACCEPT',
1269
+ * // '*' ]
1270
+ * console.log(request.rawHeaders);
1271
+ * ```
1272
+ * @since v8.4.0
1273
+ */
603
1274
  readonly rawHeaders: string[];
1275
+ /**
1276
+ * The raw request/response trailer keys and values exactly as they were
1277
+ * received. Only populated at the `'end'` event.
1278
+ * @since v8.4.0
1279
+ */
604
1280
  readonly rawTrailers: string[];
1281
+ /**
1282
+ * The request scheme pseudo header field indicating the scheme
1283
+ * portion of the target URL.
1284
+ * @since v8.4.0
1285
+ */
605
1286
  readonly scheme: string;
1287
+ /**
1288
+ * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
1289
+ * applies getters, setters, and methods based on HTTP/2 logic.
1290
+ *
1291
+ * `destroyed`, `readable`, and `writable` properties will be retrieved from and
1292
+ * set on `request.stream`.
1293
+ *
1294
+ * `destroy`, `emit`, `end`, `on` and `once` methods will be called on`request.stream`.
1295
+ *
1296
+ * `setTimeout` method will be called on `request.stream.session`.
1297
+ *
1298
+ * `pause`, `read`, `resume`, and `write` will throw an error with code`ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for
1299
+ * more information.
1300
+ *
1301
+ * All other interactions will be routed directly to the socket. With TLS support,
1302
+ * use `request.socket.getPeerCertificate()` to obtain the client's
1303
+ * authentication details.
1304
+ * @since v8.4.0
1305
+ */
606
1306
  readonly socket: net.Socket | tls.TLSSocket;
1307
+ /**
1308
+ * The `Http2Stream` object backing the request.
1309
+ * @since v8.4.0
1310
+ */
607
1311
  readonly stream: ServerHttp2Stream;
1312
+ /**
1313
+ * The request/response trailers object. Only populated at the `'end'` event.
1314
+ * @since v8.4.0
1315
+ */
608
1316
  readonly trailers: IncomingHttpHeaders;
1317
+ /**
1318
+ * Request URL string. This contains only the URL that is present in the actual
1319
+ * HTTP request. If the request is:
1320
+ *
1321
+ * ```http
1322
+ * GET /status?name=ryan HTTP/1.1
1323
+ * Accept: text/plain
1324
+ * ```
1325
+ *
1326
+ * Then `request.url` will be:
1327
+ *
1328
+ * ```js
1329
+ * '/status?name=ryan'
1330
+ * ```
1331
+ *
1332
+ * To parse the url into its parts, `new URL()` can be used:
1333
+ *
1334
+ * ```console
1335
+ * $ node
1336
+ * > new URL('/status?name=ryan', 'http://example.com')
1337
+ * URL {
1338
+ * href: 'http://example.com/status?name=ryan',
1339
+ * origin: 'http://example.com',
1340
+ * protocol: 'http:',
1341
+ * username: '',
1342
+ * password: '',
1343
+ * host: 'example.com',
1344
+ * hostname: 'example.com',
1345
+ * port: '',
1346
+ * pathname: '/status',
1347
+ * search: '?name=ryan',
1348
+ * searchParams: URLSearchParams { 'name' => 'ryan' },
1349
+ * hash: ''
1350
+ * }
1351
+ * ```
1352
+ * @since v8.4.0
1353
+ */
609
1354
  readonly url: string;
610
-
1355
+ /**
1356
+ * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
1357
+ * provided, then it is added as a listener on the `'timeout'` event on
1358
+ * the response object.
1359
+ *
1360
+ * If no `'timeout'` listener is added to the request, the response, or
1361
+ * the server, then `Http2Stream` s are destroyed when they time out. If a
1362
+ * handler is assigned to the request, the response, or the server's `'timeout'`events, timed out sockets must be handled explicitly.
1363
+ * @since v8.4.0
1364
+ */
611
1365
  setTimeout(msecs: number, callback?: () => void): void;
612
1366
  read(size?: number): Buffer | string | null;
613
-
614
- addListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
615
- addListener(event: "close", listener: () => void): this;
616
- addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
617
- addListener(event: "end", listener: () => void): this;
618
- addListener(event: "readable", listener: () => void): this;
619
- addListener(event: "error", listener: (err: Error) => void): this;
1367
+ addListener(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1368
+ addListener(event: 'close', listener: () => void): this;
1369
+ addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
1370
+ addListener(event: 'end', listener: () => void): this;
1371
+ addListener(event: 'readable', listener: () => void): this;
1372
+ addListener(event: 'error', listener: (err: Error) => void): this;
620
1373
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
621
-
622
- emit(event: "aborted", hadError: boolean, code: number): boolean;
623
- emit(event: "close"): boolean;
624
- emit(event: "data", chunk: Buffer | string): boolean;
625
- emit(event: "end"): boolean;
626
- emit(event: "readable"): boolean;
627
- emit(event: "error", err: Error): boolean;
1374
+ emit(event: 'aborted', hadError: boolean, code: number): boolean;
1375
+ emit(event: 'close'): boolean;
1376
+ emit(event: 'data', chunk: Buffer | string): boolean;
1377
+ emit(event: 'end'): boolean;
1378
+ emit(event: 'readable'): boolean;
1379
+ emit(event: 'error', err: Error): boolean;
628
1380
  emit(event: string | symbol, ...args: any[]): boolean;
629
-
630
- on(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
631
- on(event: "close", listener: () => void): this;
632
- on(event: "data", listener: (chunk: Buffer | string) => void): this;
633
- on(event: "end", listener: () => void): this;
634
- on(event: "readable", listener: () => void): this;
635
- on(event: "error", listener: (err: Error) => void): this;
1381
+ on(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1382
+ on(event: 'close', listener: () => void): this;
1383
+ on(event: 'data', listener: (chunk: Buffer | string) => void): this;
1384
+ on(event: 'end', listener: () => void): this;
1385
+ on(event: 'readable', listener: () => void): this;
1386
+ on(event: 'error', listener: (err: Error) => void): this;
636
1387
  on(event: string | symbol, listener: (...args: any[]) => void): this;
637
-
638
- once(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
639
- once(event: "close", listener: () => void): this;
640
- once(event: "data", listener: (chunk: Buffer | string) => void): this;
641
- once(event: "end", listener: () => void): this;
642
- once(event: "readable", listener: () => void): this;
643
- once(event: "error", listener: (err: Error) => void): this;
1388
+ once(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1389
+ once(event: 'close', listener: () => void): this;
1390
+ once(event: 'data', listener: (chunk: Buffer | string) => void): this;
1391
+ once(event: 'end', listener: () => void): this;
1392
+ once(event: 'readable', listener: () => void): this;
1393
+ once(event: 'error', listener: (err: Error) => void): this;
644
1394
  once(event: string | symbol, listener: (...args: any[]) => void): this;
645
-
646
- prependListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
647
- prependListener(event: "close", listener: () => void): this;
648
- prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
649
- prependListener(event: "end", listener: () => void): this;
650
- prependListener(event: "readable", listener: () => void): this;
651
- prependListener(event: "error", listener: (err: Error) => void): this;
1395
+ prependListener(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1396
+ prependListener(event: 'close', listener: () => void): this;
1397
+ prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
1398
+ prependListener(event: 'end', listener: () => void): this;
1399
+ prependListener(event: 'readable', listener: () => void): this;
1400
+ prependListener(event: 'error', listener: (err: Error) => void): this;
652
1401
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
653
-
654
- prependOnceListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
655
- prependOnceListener(event: "close", listener: () => void): this;
656
- prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
657
- prependOnceListener(event: "end", listener: () => void): this;
658
- prependOnceListener(event: "readable", listener: () => void): this;
659
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
1402
+ prependOnceListener(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1403
+ prependOnceListener(event: 'close', listener: () => void): this;
1404
+ prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
1405
+ prependOnceListener(event: 'end', listener: () => void): this;
1406
+ prependOnceListener(event: 'readable', listener: () => void): this;
1407
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
660
1408
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
661
1409
  }
662
-
1410
+ /**
1411
+ * This object is created internally by an HTTP server, not by the user. It is
1412
+ * passed as the second parameter to the `'request'` event.
1413
+ * @since v8.4.0
1414
+ */
663
1415
  export class Http2ServerResponse extends stream.Writable {
664
1416
  constructor(stream: ServerHttp2Stream);
665
-
1417
+ /**
1418
+ * See `response.socket`.
1419
+ * @since v8.4.0
1420
+ * @deprecated Since v13.0.0 - Deprecated. Use `socket`.
1421
+ */
666
1422
  readonly connection: net.Socket | tls.TLSSocket;
1423
+ /**
1424
+ * Boolean value that indicates whether the response has completed. Starts
1425
+ * as `false`. After `response.end()` executes, the value will be `true`.
1426
+ * @since v8.4.0
1427
+ * @deprecated Since v13.4.0,v12.16.0 - Deprecated. Use `writableEnded`.
1428
+ */
667
1429
  readonly finished: boolean;
1430
+ /**
1431
+ * True if headers were sent, false otherwise (read-only).
1432
+ * @since v8.4.0
1433
+ */
668
1434
  readonly headersSent: boolean;
669
1435
  readonly socket: net.Socket | tls.TLSSocket;
670
1436
  readonly stream: ServerHttp2Stream;
671
1437
  sendDate: boolean;
672
1438
  statusCode: number;
673
1439
  statusMessage: '';
1440
+ /**
1441
+ * This method adds HTTP trailing headers (a header but at the end of the
1442
+ * message) to the response.
1443
+ *
1444
+ * Attempting to set a header field name or value that contains invalid characters
1445
+ * will result in a `TypeError` being thrown.
1446
+ * @since v8.4.0
1447
+ */
674
1448
  addTrailers(trailers: OutgoingHttpHeaders): void;
1449
+ /**
1450
+ * This method signals to the server that all of the response headers and body
1451
+ * have been sent; that server should consider this message complete.
1452
+ * The method, `response.end()`, MUST be called on each response.
1453
+ *
1454
+ * If `data` is specified, it is equivalent to calling `response.write(data, encoding)` followed by `response.end(callback)`.
1455
+ *
1456
+ * If `callback` is specified, it will be called when the response stream
1457
+ * is finished.
1458
+ * @since v8.4.0
1459
+ */
675
1460
  end(callback?: () => void): void;
676
1461
  end(data: string | Uint8Array, callback?: () => void): void;
677
1462
  end(data: string | Uint8Array, encoding: BufferEncoding, callback?: () => void): void;
1463
+ /**
1464
+ * Reads out a header that has already been queued but not sent to the client.
1465
+ * The name is case-insensitive.
1466
+ *
1467
+ * ```js
1468
+ * const contentType = response.getHeader('content-type');
1469
+ * ```
1470
+ * @since v8.4.0
1471
+ */
678
1472
  getHeader(name: string): string;
1473
+ /**
1474
+ * Returns an array containing the unique names of the current outgoing headers.
1475
+ * All header names are lowercase.
1476
+ *
1477
+ * ```js
1478
+ * response.setHeader('Foo', 'bar');
1479
+ * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
1480
+ *
1481
+ * const headerNames = response.getHeaderNames();
1482
+ * // headerNames === ['foo', 'set-cookie']
1483
+ * ```
1484
+ * @since v8.4.0
1485
+ */
679
1486
  getHeaderNames(): string[];
1487
+ /**
1488
+ * Returns a shallow copy of the current outgoing headers. Since a shallow copy
1489
+ * is used, array values may be mutated without additional calls to various
1490
+ * header-related http module methods. The keys of the returned object are the
1491
+ * header names and the values are the respective header values. All header names
1492
+ * are lowercase.
1493
+ *
1494
+ * The object returned by the `response.getHeaders()` method _does not_prototypically inherit from the JavaScript `Object`. This means that typical`Object` methods such as `obj.toString()`,
1495
+ * `obj.hasOwnProperty()`, and others
1496
+ * are not defined and _will not work_.
1497
+ *
1498
+ * ```js
1499
+ * response.setHeader('Foo', 'bar');
1500
+ * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
1501
+ *
1502
+ * const headers = response.getHeaders();
1503
+ * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
1504
+ * ```
1505
+ * @since v8.4.0
1506
+ */
680
1507
  getHeaders(): OutgoingHttpHeaders;
1508
+ /**
1509
+ * Returns `true` if the header identified by `name` is currently set in the
1510
+ * outgoing headers. The header name matching is case-insensitive.
1511
+ *
1512
+ * ```js
1513
+ * const hasContentType = response.hasHeader('content-type');
1514
+ * ```
1515
+ * @since v8.4.0
1516
+ */
681
1517
  hasHeader(name: string): boolean;
1518
+ /**
1519
+ * Removes a header that has been queued for implicit sending.
1520
+ *
1521
+ * ```js
1522
+ * response.removeHeader('Content-Encoding');
1523
+ * ```
1524
+ * @since v8.4.0
1525
+ */
682
1526
  removeHeader(name: string): void;
1527
+ /**
1528
+ * Sets a single header value for implicit headers. If this header already exists
1529
+ * in the to-be-sent headers, its value will be replaced. Use an array of strings
1530
+ * here to send multiple headers with the same name.
1531
+ *
1532
+ * ```js
1533
+ * response.setHeader('Content-Type', 'text/html; charset=utf-8');
1534
+ * ```
1535
+ *
1536
+ * or
1537
+ *
1538
+ * ```js
1539
+ * response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
1540
+ * ```
1541
+ *
1542
+ * Attempting to set a header field name or value that contains invalid characters
1543
+ * will result in a `TypeError` being thrown.
1544
+ *
1545
+ * When headers have been set with `response.setHeader()`, they will be merged
1546
+ * with any headers passed to `response.writeHead()`, with the headers passed
1547
+ * to `response.writeHead()` given precedence.
1548
+ *
1549
+ * ```js
1550
+ * // Returns content-type = text/plain
1551
+ * const server = http2.createServer((req, res) => {
1552
+ * res.setHeader('Content-Type', 'text/html; charset=utf-8');
1553
+ * res.setHeader('X-Foo', 'bar');
1554
+ * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
1555
+ * res.end('ok');
1556
+ * });
1557
+ * ```
1558
+ * @since v8.4.0
1559
+ */
683
1560
  setHeader(name: string, value: number | string | ReadonlyArray<string>): void;
1561
+ /**
1562
+ * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
1563
+ * provided, then it is added as a listener on the `'timeout'` event on
1564
+ * the response object.
1565
+ *
1566
+ * If no `'timeout'` listener is added to the request, the response, or
1567
+ * the server, then `Http2Stream` s are destroyed when they time out. If a
1568
+ * handler is assigned to the request, the response, or the server's `'timeout'`events, timed out sockets must be handled explicitly.
1569
+ * @since v8.4.0
1570
+ */
684
1571
  setTimeout(msecs: number, callback?: () => void): void;
1572
+ /**
1573
+ * If this method is called and `response.writeHead()` has not been called,
1574
+ * it will switch to implicit header mode and flush the implicit headers.
1575
+ *
1576
+ * This sends a chunk of the response body. This method may
1577
+ * be called multiple times to provide successive parts of the body.
1578
+ *
1579
+ * In the `http` module, the response body is omitted when the
1580
+ * request is a HEAD request. Similarly, the `204` and `304` responses_must not_ include a message body.
1581
+ *
1582
+ * `chunk` can be a string or a buffer. If `chunk` is a string,
1583
+ * the second parameter specifies how to encode it into a byte stream.
1584
+ * By default the `encoding` is `'utf8'`. `callback` will be called when this chunk
1585
+ * of data is flushed.
1586
+ *
1587
+ * This is the raw HTTP body and has nothing to do with higher-level multi-part
1588
+ * body encodings that may be used.
1589
+ *
1590
+ * The first time `response.write()` is called, it will send the buffered
1591
+ * header information and the first chunk of the body to the client. The second
1592
+ * time `response.write()` is called, Node.js assumes data will be streamed,
1593
+ * and sends the new data separately. That is, the response is buffered up to the
1594
+ * first chunk of the body.
1595
+ *
1596
+ * Returns `true` if the entire data was flushed successfully to the kernel
1597
+ * buffer. Returns `false` if all or part of the data was queued in user memory.`'drain'` will be emitted when the buffer is free again.
1598
+ * @since v8.4.0
1599
+ */
685
1600
  write(chunk: string | Uint8Array, callback?: (err: Error) => void): boolean;
686
1601
  write(chunk: string | Uint8Array, encoding: BufferEncoding, callback?: (err: Error) => void): boolean;
1602
+ /**
1603
+ * Sends a status `100 Continue` to the client, indicating that the request body
1604
+ * should be sent. See the `'checkContinue'` event on `Http2Server` and`Http2SecureServer`.
1605
+ * @since v8.4.0
1606
+ */
687
1607
  writeContinue(): void;
1608
+ /**
1609
+ * Sends a response header to the request. The status code is a 3-digit HTTP
1610
+ * status code, like `404`. The last argument, `headers`, are the response headers.
1611
+ *
1612
+ * Returns a reference to the `Http2ServerResponse`, so that calls can be chained.
1613
+ *
1614
+ * For compatibility with `HTTP/1`, a human-readable `statusMessage` may be
1615
+ * passed as the second argument. However, because the `statusMessage` has no
1616
+ * meaning within HTTP/2, the argument will have no effect and a process warning
1617
+ * will be emitted.
1618
+ *
1619
+ * ```js
1620
+ * const body = 'hello world';
1621
+ * response.writeHead(200, {
1622
+ * 'Content-Length': Buffer.byteLength(body),
1623
+ * 'Content-Type': 'text/plain; charset=utf-8',
1624
+ * });
1625
+ * ```
1626
+ *
1627
+ * `Content-Length` is given in bytes not characters. The`Buffer.byteLength()` API may be used to determine the number of bytes in a
1628
+ * given encoding. On outbound messages, Node.js does not check if Content-Length
1629
+ * and the length of the body being transmitted are equal or not. However, when
1630
+ * receiving messages, Node.js will automatically reject messages when the`Content-Length` does not match the actual payload size.
1631
+ *
1632
+ * This method may be called at most one time on a message before `response.end()` is called.
1633
+ *
1634
+ * If `response.write()` or `response.end()` are called before calling
1635
+ * this, the implicit/mutable headers will be calculated and call this function.
1636
+ *
1637
+ * When headers have been set with `response.setHeader()`, they will be merged
1638
+ * with any headers passed to `response.writeHead()`, with the headers passed
1639
+ * to `response.writeHead()` given precedence.
1640
+ *
1641
+ * ```js
1642
+ * // Returns content-type = text/plain
1643
+ * const server = http2.createServer((req, res) => {
1644
+ * res.setHeader('Content-Type', 'text/html; charset=utf-8');
1645
+ * res.setHeader('X-Foo', 'bar');
1646
+ * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
1647
+ * res.end('ok');
1648
+ * });
1649
+ * ```
1650
+ *
1651
+ * Attempting to set a header field name or value that contains invalid characters
1652
+ * will result in a `TypeError` being thrown.
1653
+ * @since v8.4.0
1654
+ */
688
1655
  writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this;
689
1656
  writeHead(statusCode: number, statusMessage: string, headers?: OutgoingHttpHeaders): this;
1657
+ /**
1658
+ * Call {@link tream.pushStream} with the given headers, and wrap the
1659
+ * given `Http2Stream` on a newly created `Http2ServerResponse` as the callback
1660
+ * parameter if successful. When `Http2ServerRequest` is closed, the callback is
1661
+ * called with an error `ERR_HTTP2_INVALID_STREAM`.
1662
+ * @since v8.4.0
1663
+ * @param headers An object describing the headers
1664
+ * @param callback Called once `http2stream.pushStream()` is finished, or either when the attempt to create the pushed `Http2Stream` has failed or has been rejected, or the state of
1665
+ * `Http2ServerRequest` is closed prior to calling the `http2stream.pushStream()` method
1666
+ */
690
1667
  createPushResponse(headers: OutgoingHttpHeaders, callback: (err: Error | null, res: Http2ServerResponse) => void): void;
691
-
692
- addListener(event: "close", listener: () => void): this;
693
- addListener(event: "drain", listener: () => void): this;
694
- addListener(event: "error", listener: (error: Error) => void): this;
695
- addListener(event: "finish", listener: () => void): this;
696
- addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
697
- addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
1668
+ addListener(event: 'close', listener: () => void): this;
1669
+ addListener(event: 'drain', listener: () => void): this;
1670
+ addListener(event: 'error', listener: (error: Error) => void): this;
1671
+ addListener(event: 'finish', listener: () => void): this;
1672
+ addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
1673
+ addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
698
1674
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
699
-
700
- emit(event: "close"): boolean;
701
- emit(event: "drain"): boolean;
702
- emit(event: "error", error: Error): boolean;
703
- emit(event: "finish"): boolean;
704
- emit(event: "pipe", src: stream.Readable): boolean;
705
- emit(event: "unpipe", src: stream.Readable): boolean;
1675
+ emit(event: 'close'): boolean;
1676
+ emit(event: 'drain'): boolean;
1677
+ emit(event: 'error', error: Error): boolean;
1678
+ emit(event: 'finish'): boolean;
1679
+ emit(event: 'pipe', src: stream.Readable): boolean;
1680
+ emit(event: 'unpipe', src: stream.Readable): boolean;
706
1681
  emit(event: string | symbol, ...args: any[]): boolean;
707
-
708
- on(event: "close", listener: () => void): this;
709
- on(event: "drain", listener: () => void): this;
710
- on(event: "error", listener: (error: Error) => void): this;
711
- on(event: "finish", listener: () => void): this;
712
- on(event: "pipe", listener: (src: stream.Readable) => void): this;
713
- on(event: "unpipe", listener: (src: stream.Readable) => void): this;
1682
+ on(event: 'close', listener: () => void): this;
1683
+ on(event: 'drain', listener: () => void): this;
1684
+ on(event: 'error', listener: (error: Error) => void): this;
1685
+ on(event: 'finish', listener: () => void): this;
1686
+ on(event: 'pipe', listener: (src: stream.Readable) => void): this;
1687
+ on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
714
1688
  on(event: string | symbol, listener: (...args: any[]) => void): this;
715
-
716
- once(event: "close", listener: () => void): this;
717
- once(event: "drain", listener: () => void): this;
718
- once(event: "error", listener: (error: Error) => void): this;
719
- once(event: "finish", listener: () => void): this;
720
- once(event: "pipe", listener: (src: stream.Readable) => void): this;
721
- once(event: "unpipe", listener: (src: stream.Readable) => void): this;
1689
+ once(event: 'close', listener: () => void): this;
1690
+ once(event: 'drain', listener: () => void): this;
1691
+ once(event: 'error', listener: (error: Error) => void): this;
1692
+ once(event: 'finish', listener: () => void): this;
1693
+ once(event: 'pipe', listener: (src: stream.Readable) => void): this;
1694
+ once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
722
1695
  once(event: string | symbol, listener: (...args: any[]) => void): this;
723
-
724
- prependListener(event: "close", listener: () => void): this;
725
- prependListener(event: "drain", listener: () => void): this;
726
- prependListener(event: "error", listener: (error: Error) => void): this;
727
- prependListener(event: "finish", listener: () => void): this;
728
- prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
729
- prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
1696
+ prependListener(event: 'close', listener: () => void): this;
1697
+ prependListener(event: 'drain', listener: () => void): this;
1698
+ prependListener(event: 'error', listener: (error: Error) => void): this;
1699
+ prependListener(event: 'finish', listener: () => void): this;
1700
+ prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
1701
+ prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
730
1702
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
731
-
732
- prependOnceListener(event: "close", listener: () => void): this;
733
- prependOnceListener(event: "drain", listener: () => void): this;
734
- prependOnceListener(event: "error", listener: (error: Error) => void): this;
735
- prependOnceListener(event: "finish", listener: () => void): this;
736
- prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
737
- prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
1703
+ prependOnceListener(event: 'close', listener: () => void): this;
1704
+ prependOnceListener(event: 'drain', listener: () => void): this;
1705
+ prependOnceListener(event: 'error', listener: (error: Error) => void): this;
1706
+ prependOnceListener(event: 'finish', listener: () => void): this;
1707
+ prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
1708
+ prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
738
1709
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
739
1710
  }
740
-
741
- // Public API
742
-
743
1711
  export namespace constants {
744
1712
  const NGHTTP2_SESSION_SERVER: number;
745
1713
  const NGHTTP2_SESSION_CLIENT: number;
@@ -950,23 +1918,117 @@ declare module 'http2' {
950
1918
  const HTTP_STATUS_NOT_EXTENDED: number;
951
1919
  const HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED: number;
952
1920
  }
953
-
954
1921
  /**
955
1922
  * This symbol can be set as a property on the HTTP/2 headers object with
956
1923
  * an array value in order to provide a list of headers considered sensitive.
957
1924
  */
958
1925
  export const sensitiveHeaders: symbol;
959
-
1926
+ /**
1927
+ * Returns an object containing the default settings for an `Http2Session`instance. This method returns a new object instance every time it is called
1928
+ * so instances returned may be safely modified for use.
1929
+ * @since v8.4.0
1930
+ */
960
1931
  export function getDefaultSettings(): Settings;
1932
+ /**
1933
+ * Returns a `Buffer` instance containing serialized representation of the given
1934
+ * HTTP/2 settings as specified in the [HTTP/2](https://tools.ietf.org/html/rfc7540) specification. This is intended
1935
+ * for use with the `HTTP2-Settings` header field.
1936
+ *
1937
+ * ```js
1938
+ * const http2 = require('http2');
1939
+ *
1940
+ * const packed = http2.getPackedSettings({ enablePush: false });
1941
+ *
1942
+ * console.log(packed.toString('base64'));
1943
+ * // Prints: AAIAAAAA
1944
+ * ```
1945
+ * @since v8.4.0
1946
+ */
961
1947
  export function getPackedSettings(settings: Settings): Buffer;
1948
+ /**
1949
+ * Returns a `HTTP/2 Settings Object` containing the deserialized settings from
1950
+ * the given `Buffer` as generated by `http2.getPackedSettings()`.
1951
+ * @since v8.4.0
1952
+ * @param buf The packed settings.
1953
+ */
962
1954
  export function getUnpackedSettings(buf: Uint8Array): Settings;
963
-
1955
+ /**
1956
+ * Returns a `net.Server` instance that creates and manages `Http2Session`instances.
1957
+ *
1958
+ * Since there are no browsers known that support[unencrypted HTTP/2](https://http2.github.io/faq/#does-http2-require-encryption), the use of {@link createSecureServer} is necessary when
1959
+ * communicating
1960
+ * with browser clients.
1961
+ *
1962
+ * ```js
1963
+ * const http2 = require('http2');
1964
+ *
1965
+ * // Create an unencrypted HTTP/2 server.
1966
+ * // Since there are no browsers known that support
1967
+ * // unencrypted HTTP/2, the use of `http2.createSecureServer()`
1968
+ * // is necessary when communicating with browser clients.
1969
+ * const server = http2.createServer();
1970
+ *
1971
+ * server.on('stream', (stream, headers) => {
1972
+ * stream.respond({
1973
+ * 'content-type': 'text/html; charset=utf-8',
1974
+ * ':status': 200
1975
+ * });
1976
+ * stream.end('<h1>Hello World</h1>');
1977
+ * });
1978
+ *
1979
+ * server.listen(80);
1980
+ * ```
1981
+ * @since v8.4.0
1982
+ * @param onRequestHandler See `Compatibility API`
1983
+ */
964
1984
  export function createServer(onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2Server;
965
1985
  export function createServer(options: ServerOptions, onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2Server;
966
-
1986
+ /**
1987
+ * Returns a `tls.Server` instance that creates and manages `Http2Session`instances.
1988
+ *
1989
+ * ```js
1990
+ * const http2 = require('http2');
1991
+ * const fs = require('fs');
1992
+ *
1993
+ * const options = {
1994
+ * key: fs.readFileSync('server-key.pem'),
1995
+ * cert: fs.readFileSync('server-cert.pem')
1996
+ * };
1997
+ *
1998
+ * // Create a secure HTTP/2 server
1999
+ * const server = http2.createSecureServer(options);
2000
+ *
2001
+ * server.on('stream', (stream, headers) => {
2002
+ * stream.respond({
2003
+ * 'content-type': 'text/html; charset=utf-8',
2004
+ * ':status': 200
2005
+ * });
2006
+ * stream.end('<h1>Hello World</h1>');
2007
+ * });
2008
+ *
2009
+ * server.listen(80);
2010
+ * ```
2011
+ * @since v8.4.0
2012
+ * @param onRequestHandler See `Compatibility API`
2013
+ */
967
2014
  export function createSecureServer(onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2SecureServer;
968
2015
  export function createSecureServer(options: SecureServerOptions, onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2SecureServer;
969
-
2016
+ /**
2017
+ * Returns a `ClientHttp2Session` instance.
2018
+ *
2019
+ * ```js
2020
+ * const http2 = require('http2');
2021
+ * const client = http2.connect('https://localhost:1234');
2022
+ *
2023
+ * // Use the client
2024
+ *
2025
+ * client.close();
2026
+ * ```
2027
+ * @since v8.4.0
2028
+ * @param authority The remote HTTP/2 server to connect to. This must be in the form of a minimal, valid URL with the `http://` or `https://` prefix, host name, and IP port (if a non-default port
2029
+ * is used). Userinfo (user ID and password), path, querystring, and fragment details in the URL will be ignored.
2030
+ * @param listener Will be registered as a one-time listener of the {@link 'connect'} event.
2031
+ */
970
2032
  export function connect(authority: string | url.URL, listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): ClientHttp2Session;
971
2033
  export function connect(
972
2034
  authority: string | url.URL,
@@ -974,7 +2036,6 @@ declare module 'http2' {
974
2036
  listener?: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void
975
2037
  ): ClientHttp2Session;
976
2038
  }
977
-
978
2039
  declare module 'node:http2' {
979
2040
  export * from 'http2';
980
2041
  }