m06_task3.js 1.0.0

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