@node-red/editor-client 3.0.2 → 3.1.0-beta.2

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