UNPKG

112 kBTypeScriptView Raw
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/v17.0.0/lib/http2.js)
10 */
11declare 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 the `true` if the `END_STREAM` flag was set in the request or response
87 * HEADERS frame received, indicating that no additional data should be received
88 * and the readable side of the `Http2Stream` will be closed.
89 * @since v10.11.0
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 }
584 export interface SessionState {
585 effectiveLocalWindowSize?: number | undefined;
586 effectiveRecvDataLength?: number | undefined;
587 nextStreamID?: number | undefined;
588 localWindowSize?: number | undefined;
589 lastProcStreamID?: number | undefined;
590 remoteWindowSize?: number | undefined;
591 outboundQueueSize?: number | undefined;
592 deflateDynamicTableSize?: number | undefined;
593 inflateDynamicTableSize?: number | undefined;
594 }
595 export interface Http2Session extends EventEmitter {
596 /**
597 * Value will be `undefined` if the `Http2Session` is not yet connected to a
598 * socket, `h2c` if the `Http2Session` is not connected to a `TLSSocket`, or
599 * will return the value of the connected `TLSSocket`'s own `alpnProtocol`property.
600 * @since v9.4.0
601 */
602 readonly alpnProtocol?: string | undefined;
603 /**
604 * Will be `true` if this `Http2Session` instance has been closed, otherwise`false`.
605 * @since v9.4.0
606 */
607 readonly closed: boolean;
608 /**
609 * Will be `true` if this `Http2Session` instance is still connecting, will be set
610 * to `false` before emitting `connect` event and/or calling the `http2.connect`callback.
611 * @since v10.0.0
612 */
613 readonly connecting: boolean;
614 /**
615 * Will be `true` if this `Http2Session` instance has been destroyed and must no
616 * longer be used, otherwise `false`.
617 * @since v8.4.0
618 */
619 readonly destroyed: boolean;
620 /**
621 * Value is `undefined` if the `Http2Session` session socket has not yet been
622 * connected, `true` if the `Http2Session` is connected with a `TLSSocket`,
623 * and `false` if the `Http2Session` is connected to any other kind of socket
624 * or stream.
625 * @since v9.4.0
626 */
627 readonly encrypted?: boolean | undefined;
628 /**
629 * A prototype-less object describing the current local settings of this`Http2Session`. The local settings are local to _this_`Http2Session` instance.
630 * @since v8.4.0
631 */
632 readonly localSettings: Settings;
633 /**
634 * If the `Http2Session` is connected to a `TLSSocket`, the `originSet` property
635 * will return an `Array` of origins for which the `Http2Session` may be
636 * considered authoritative.
637 *
638 * The `originSet` property is only available when using a secure TLS connection.
639 * @since v9.4.0
640 */
641 readonly originSet?: string[] | undefined;
642 /**
643 * Indicates whether the `Http2Session` is currently waiting for acknowledgment of
644 * a sent `SETTINGS` frame. Will be `true` after calling the`http2session.settings()` method. Will be `false` once all sent `SETTINGS`frames have been acknowledged.
645 * @since v8.4.0
646 */
647 readonly pendingSettingsAck: boolean;
648 /**
649 * A prototype-less object describing the current remote settings of this`Http2Session`. The remote settings are set by the _connected_ HTTP/2 peer.
650 * @since v8.4.0
651 */
652 readonly remoteSettings: Settings;
653 /**
654 * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
655 * limits available methods to ones safe to use with HTTP/2.
656 *
657 * `destroy`, `emit`, `end`, `pause`, `read`, `resume`, and `write` will throw
658 * an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for more information.
659 *
660 * `setTimeout` method will be called on this `Http2Session`.
661 *
662 * All other interactions will be routed directly to the socket.
663 * @since v8.4.0
664 */
665 readonly socket: net.Socket | tls.TLSSocket;
666 /**
667 * Provides miscellaneous information about the current state of the`Http2Session`.
668 *
669 * An object describing the current status of this `Http2Session`.
670 * @since v8.4.0
671 */
672 readonly state: SessionState;
673 /**
674 * The `http2session.type` will be equal to`http2.constants.NGHTTP2_SESSION_SERVER` if this `Http2Session` instance is a
675 * server, and `http2.constants.NGHTTP2_SESSION_CLIENT` if the instance is a
676 * client.
677 * @since v8.4.0
678 */
679 readonly type: number;
680 /**
681 * Gracefully closes the `Http2Session`, allowing any existing streams to
682 * complete on their own and preventing new `Http2Stream` instances from being
683 * created. Once closed, `http2session.destroy()`_might_ be called if there
684 * are no open `Http2Stream` instances.
685 *
686 * If specified, the `callback` function is registered as a handler for the`'close'` event.
687 * @since v9.4.0
688 */
689 close(callback?: () => void): void;
690 /**
691 * Immediately terminates the `Http2Session` and the associated `net.Socket` or`tls.TLSSocket`.
692 *
693 * Once destroyed, the `Http2Session` will emit the `'close'` event. If `error`is not undefined, an `'error'` event will be emitted immediately before the`'close'` event.
694 *
695 * If there are any remaining open `Http2Streams` associated with the`Http2Session`, those will also be destroyed.
696 * @since v8.4.0
697 * @param error An `Error` object if the `Http2Session` is being destroyed due to an error.
698 * @param code The HTTP/2 error code to send in the final `GOAWAY` frame. If unspecified, and `error` is not undefined, the default is `INTERNAL_ERROR`, otherwise defaults to `NO_ERROR`.
699 */
700 destroy(error?: Error, code?: number): void;
701 /**
702 * Transmits a `GOAWAY` frame to the connected peer _without_ shutting down the`Http2Session`.
703 * @since v9.4.0
704 * @param code An HTTP/2 error code
705 * @param lastStreamID The numeric ID of the last processed `Http2Stream`
706 * @param opaqueData A `TypedArray` or `DataView` instance containing additional data to be carried within the `GOAWAY` frame.
707 */
708 goaway(code?: number, lastStreamID?: number, opaqueData?: NodeJS.ArrayBufferView): void;
709 /**
710 * Sends a `PING` frame to the connected HTTP/2 peer. A `callback` function must
711 * be provided. The method will return `true` if the `PING` was sent, `false`otherwise.
712 *
713 * The maximum number of outstanding (unacknowledged) pings is determined by the`maxOutstandingPings` configuration option. The default maximum is 10.
714 *
715 * If provided, the `payload` must be a `Buffer`, `TypedArray`, or `DataView`containing 8 bytes of data that will be transmitted with the `PING` and
716 * returned with the ping acknowledgment.
717 *
718 * The callback will be invoked with three arguments: an error argument that will
719 * be `null` if the `PING` was successfully acknowledged, a `duration` argument
720 * that reports the number of milliseconds elapsed since the ping was sent and the
721 * acknowledgment was received, and a `Buffer` containing the 8-byte `PING`payload.
722 *
723 * ```js
724 * session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
725 * if (!err) {
726 * console.log(`Ping acknowledged in ${duration} milliseconds`);
727 * console.log(`With payload '${payload.toString()}'`);
728 * }
729 * });
730 * ```
731 *
732 * If the `payload` argument is not specified, the default payload will be the
733 * 64-bit timestamp (little endian) marking the start of the `PING` duration.
734 * @since v8.9.3
735 * @param payload Optional ping payload.
736 */
737 ping(callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean;
738 ping(payload: NodeJS.ArrayBufferView, callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean;
739 /**
740 * Calls `ref()` on this `Http2Session`instance's underlying `net.Socket`.
741 * @since v9.4.0
742 */
743 ref(): void;
744 /**
745 * Sets the local endpoint's window size.
746 * The `windowSize` is the total window size to set, not
747 * the delta.
748 *
749 * ```js
750 * const http2 = require('http2');
751 *
752 * const server = http2.createServer();
753 * const expectedWindowSize = 2 ** 20;
754 * server.on('connect', (session) => {
755 *
756 * // Set local window size to be 2 ** 20
757 * session.setLocalWindowSize(expectedWindowSize);
758 * });
759 * ```
760 * @since v15.3.0, v14.18.0
761 */
762 setLocalWindowSize(windowSize: number): void;
763 /**
764 * Used to set a callback function that is called when there is no activity on
765 * the `Http2Session` after `msecs` milliseconds. The given `callback` is
766 * registered as a listener on the `'timeout'` event.
767 * @since v8.4.0
768 */
769 setTimeout(msecs: number, callback?: () => void): void;
770 /**
771 * Updates the current local settings for this `Http2Session` and sends a new`SETTINGS` frame to the connected HTTP/2 peer.
772 *
773 * Once called, the `http2session.pendingSettingsAck` property will be `true`while the session is waiting for the remote peer to acknowledge the new
774 * settings.
775 *
776 * The new settings will not become effective until the `SETTINGS` acknowledgment
777 * is received and the `'localSettings'` event is emitted. It is possible to send
778 * multiple `SETTINGS` frames while acknowledgment is still pending.
779 * @since v8.4.0
780 * @param callback Callback that is called once the session is connected or right away if the session is already connected.
781 */
782 settings(settings: Settings): void;
783 /**
784 * Calls `unref()` on this `Http2Session`instance's underlying `net.Socket`.
785 * @since v9.4.0
786 */
787 unref(): void;
788 addListener(event: 'close', listener: () => void): this;
789 addListener(event: 'error', listener: (err: Error) => void): this;
790 addListener(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
791 addListener(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
792 addListener(event: 'localSettings', listener: (settings: Settings) => void): this;
793 addListener(event: 'ping', listener: () => void): this;
794 addListener(event: 'remoteSettings', listener: (settings: Settings) => void): this;
795 addListener(event: 'timeout', listener: () => void): this;
796 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
797 emit(event: 'close'): boolean;
798 emit(event: 'error', err: Error): boolean;
799 emit(event: 'frameError', frameType: number, errorCode: number, streamID: number): boolean;
800 emit(event: 'goaway', errorCode: number, lastStreamID: number, opaqueData: Buffer): boolean;
801 emit(event: 'localSettings', settings: Settings): boolean;
802 emit(event: 'ping'): boolean;
803 emit(event: 'remoteSettings', settings: Settings): boolean;
804 emit(event: 'timeout'): boolean;
805 emit(event: string | symbol, ...args: any[]): boolean;
806 on(event: 'close', listener: () => void): this;
807 on(event: 'error', listener: (err: Error) => void): this;
808 on(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
809 on(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
810 on(event: 'localSettings', listener: (settings: Settings) => void): this;
811 on(event: 'ping', listener: () => void): this;
812 on(event: 'remoteSettings', listener: (settings: Settings) => void): this;
813 on(event: 'timeout', listener: () => void): this;
814 on(event: string | symbol, listener: (...args: any[]) => void): this;
815 once(event: 'close', listener: () => void): this;
816 once(event: 'error', listener: (err: Error) => void): this;
817 once(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
818 once(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
819 once(event: 'localSettings', listener: (settings: Settings) => void): this;
820 once(event: 'ping', listener: () => void): this;
821 once(event: 'remoteSettings', listener: (settings: Settings) => void): this;
822 once(event: 'timeout', listener: () => void): this;
823 once(event: string | symbol, listener: (...args: any[]) => void): this;
824 prependListener(event: 'close', listener: () => void): this;
825 prependListener(event: 'error', listener: (err: Error) => void): this;
826 prependListener(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
827 prependListener(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
828 prependListener(event: 'localSettings', listener: (settings: Settings) => void): this;
829 prependListener(event: 'ping', listener: () => void): this;
830 prependListener(event: 'remoteSettings', listener: (settings: Settings) => void): this;
831 prependListener(event: 'timeout', listener: () => void): this;
832 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
833 prependOnceListener(event: 'close', listener: () => void): this;
834 prependOnceListener(event: 'error', listener: (err: Error) => void): this;
835 prependOnceListener(event: 'frameError', listener: (frameType: number, errorCode: number, streamID: number) => void): this;
836 prependOnceListener(event: 'goaway', listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
837 prependOnceListener(event: 'localSettings', listener: (settings: Settings) => void): this;
838 prependOnceListener(event: 'ping', listener: () => void): this;
839 prependOnceListener(event: 'remoteSettings', listener: (settings: Settings) => void): this;
840 prependOnceListener(event: 'timeout', listener: () => void): this;
841 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
842 }
843 export interface ClientHttp2Session extends Http2Session {
844 /**
845 * For HTTP/2 Client `Http2Session` instances only, the `http2session.request()`creates and returns an `Http2Stream` instance that can be used to send an
846 * HTTP/2 request to the connected server.
847 *
848 * This method is only available if `http2session.type` is equal to`http2.constants.NGHTTP2_SESSION_CLIENT`.
849 *
850 * ```js
851 * const http2 = require('http2');
852 * const clientSession = http2.connect('https://localhost:1234');
853 * const {
854 * HTTP2_HEADER_PATH,
855 * HTTP2_HEADER_STATUS
856 * } = http2.constants;
857 *
858 * const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
859 * req.on('response', (headers) => {
860 * console.log(headers[HTTP2_HEADER_STATUS]);
861 * req.on('data', (chunk) => { // .. });
862 * req.on('end', () => { // .. });
863 * });
864 * ```
865 *
866 * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
867 * is emitted immediately after queuing the last chunk of payload data to be sent.
868 * The `http2stream.sendTrailers()` method can then be called to send trailing
869 * headers to the peer.
870 *
871 * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
872 * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
873 *
874 * When `options.signal` is set with an `AbortSignal` and then `abort` on the
875 * corresponding `AbortController` is called, the request will emit an `'error'`event with an `AbortError` error.
876 *
877 * The `:method` and `:path` pseudo-headers are not specified within `headers`,
878 * they respectively default to:
879 *
880 * * `:method` \= `'GET'`
881 * * `:path` \= `/`
882 * @since v8.4.0
883 */
884 request(headers?: OutgoingHttpHeaders, options?: ClientSessionRequestOptions): ClientHttp2Stream;
885 addListener(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
886 addListener(event: 'origin', listener: (origins: string[]) => void): this;
887 addListener(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
888 addListener(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
889 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
890 emit(event: 'altsvc', alt: string, origin: string, stream: number): boolean;
891 emit(event: 'origin', origins: ReadonlyArray<string>): boolean;
892 emit(event: 'connect', session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
893 emit(event: 'stream', stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
894 emit(event: string | symbol, ...args: any[]): boolean;
895 on(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
896 on(event: 'origin', listener: (origins: string[]) => void): this;
897 on(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
898 on(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
899 on(event: string | symbol, listener: (...args: any[]) => void): this;
900 once(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
901 once(event: 'origin', listener: (origins: string[]) => void): this;
902 once(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
903 once(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
904 once(event: string | symbol, listener: (...args: any[]) => void): this;
905 prependListener(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
906 prependListener(event: 'origin', listener: (origins: string[]) => void): this;
907 prependListener(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
908 prependListener(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
909 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
910 prependOnceListener(event: 'altsvc', listener: (alt: string, origin: string, stream: number) => void): this;
911 prependOnceListener(event: 'origin', listener: (origins: string[]) => void): this;
912 prependOnceListener(event: 'connect', listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
913 prependOnceListener(event: 'stream', listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
914 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
915 }
916 export interface AlternativeServiceOptions {
917 origin: number | string | url.URL;
918 }
919 export interface ServerHttp2Session extends Http2Session {
920 readonly server: Http2Server | Http2SecureServer;
921 /**
922 * Submits an `ALTSVC` frame (as defined by [RFC 7838](https://tools.ietf.org/html/rfc7838)) to the connected client.
923 *
924 * ```js
925 * const http2 = require('http2');
926 *
927 * const server = http2.createServer();
928 * server.on('session', (session) => {
929 * // Set altsvc for origin https://example.org:80
930 * session.altsvc('h2=":8000"', 'https://example.org:80');
931 * });
932 *
933 * server.on('stream', (stream) => {
934 * // Set altsvc for a specific stream
935 * stream.session.altsvc('h2=":8000"', stream.id);
936 * });
937 * ```
938 *
939 * Sending an `ALTSVC` frame with a specific stream ID indicates that the alternate
940 * service is associated with the origin of the given `Http2Stream`.
941 *
942 * The `alt` and origin string _must_ contain only ASCII bytes and are
943 * strictly interpreted as a sequence of ASCII bytes. The special value `'clear'`may be passed to clear any previously set alternative service for a given
944 * domain.
945 *
946 * When a string is passed for the `originOrStream` argument, it will be parsed as
947 * a URL and the origin will be derived. For instance, the origin for the
948 * HTTP URL `'https://example.org/foo/bar'` is the ASCII string`'https://example.org'`. An error will be thrown if either the given string
949 * cannot be parsed as a URL or if a valid origin cannot be derived.
950 *
951 * A `URL` object, or any object with an `origin` property, may be passed as`originOrStream`, in which case the value of the `origin` property will be
952 * used. The value of the `origin` property _must_ be a properly serialized
953 * ASCII origin.
954 * @since v9.4.0
955 * @param alt A description of the alternative service configuration as defined by `RFC 7838`.
956 * @param originOrStream Either a URL string specifying the origin (or an `Object` with an `origin` property) or the numeric identifier of an active `Http2Stream` as given by the
957 * `http2stream.id` property.
958 */
959 altsvc(alt: string, originOrStream: number | string | url.URL | AlternativeServiceOptions): void;
960 /**
961 * Submits an `ORIGIN` frame (as defined by [RFC 8336](https://tools.ietf.org/html/rfc8336)) to the connected client
962 * to advertise the set of origins for which the server is capable of providing
963 * authoritative responses.
964 *
965 * ```js
966 * const http2 = require('http2');
967 * const options = getSecureOptionsSomehow();
968 * const server = http2.createSecureServer(options);
969 * server.on('stream', (stream) => {
970 * stream.respond();
971 * stream.end('ok');
972 * });
973 * server.on('session', (session) => {
974 * session.origin('https://example.com', 'https://example.org');
975 * });
976 * ```
977 *
978 * When a string is passed as an `origin`, it will be parsed as a URL and the
979 * origin will be derived. For instance, the origin for the HTTP URL`'https://example.org/foo/bar'` is the ASCII string`'https://example.org'`. An error will be thrown if either the given
980 * string
981 * cannot be parsed as a URL or if a valid origin cannot be derived.
982 *
983 * A `URL` object, or any object with an `origin` property, may be passed as
984 * an `origin`, in which case the value of the `origin` property will be
985 * used. The value of the `origin` property _must_ be a properly serialized
986 * ASCII origin.
987 *
988 * Alternatively, the `origins` option may be used when creating a new HTTP/2
989 * server using the `http2.createSecureServer()` method:
990 *
991 * ```js
992 * const http2 = require('http2');
993 * const options = getSecureOptionsSomehow();
994 * options.origins = ['https://example.com', 'https://example.org'];
995 * const server = http2.createSecureServer(options);
996 * server.on('stream', (stream) => {
997 * stream.respond();
998 * stream.end('ok');
999 * });
1000 * ```
1001 * @since v10.12.0
1002 * @param origins One or more URL Strings passed as separate arguments.
1003 */
1004 origin(
1005 ...origins: Array<
1006 | string
1007 | url.URL
1008 | {
1009 origin: string;
1010 }
1011 >
1012 ): void;
1013 addListener(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1014 addListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1015 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1016 emit(event: 'connect', session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
1017 emit(event: 'stream', stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1018 emit(event: string | symbol, ...args: any[]): boolean;
1019 on(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1020 on(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1021 on(event: string | symbol, listener: (...args: any[]) => void): this;
1022 once(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1023 once(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1024 once(event: string | symbol, listener: (...args: any[]) => void): this;
1025 prependListener(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1026 prependListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1027 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1028 prependOnceListener(event: 'connect', listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
1029 prependOnceListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1030 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1031 }
1032 // Http2Server
1033 export interface SessionOptions {
1034 maxDeflateDynamicTableSize?: number | undefined;
1035 maxSessionMemory?: number | undefined;
1036 maxHeaderListPairs?: number | undefined;
1037 maxOutstandingPings?: number | undefined;
1038 maxSendHeaderBlockLength?: number | undefined;
1039 paddingStrategy?: number | undefined;
1040 peerMaxConcurrentStreams?: number | undefined;
1041 settings?: Settings | undefined;
1042 /**
1043 * Specifies a timeout in milliseconds that
1044 * a server should wait when an [`'unknownProtocol'`][] is emitted. If the
1045 * socket has not been destroyed by that time the server will destroy it.
1046 * @default 100000
1047 */
1048 unknownProtocolTimeout?: number | undefined;
1049 selectPadding?(frameLen: number, maxFrameLen: number): number;
1050 createConnection?(authority: url.URL, option: SessionOptions): stream.Duplex;
1051 }
1052 export interface ClientSessionOptions extends SessionOptions {
1053 maxReservedRemoteStreams?: number | undefined;
1054 createConnection?: ((authority: url.URL, option: SessionOptions) => stream.Duplex) | undefined;
1055 protocol?: 'http:' | 'https:' | undefined;
1056 }
1057 export interface ServerSessionOptions extends SessionOptions {
1058 Http1IncomingMessage?: typeof IncomingMessage | undefined;
1059 Http1ServerResponse?: typeof ServerResponse | undefined;
1060 Http2ServerRequest?: typeof Http2ServerRequest | undefined;
1061 Http2ServerResponse?: typeof Http2ServerResponse | undefined;
1062 }
1063 export interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions {}
1064 export interface SecureServerSessionOptions extends ServerSessionOptions, tls.TlsOptions {}
1065 export interface ServerOptions extends ServerSessionOptions {}
1066 export interface SecureServerOptions extends SecureServerSessionOptions {
1067 allowHTTP1?: boolean | undefined;
1068 origins?: string[] | undefined;
1069 }
1070 interface HTTP2ServerCommon {
1071 setTimeout(msec?: number, callback?: () => void): this;
1072 /**
1073 * Throws ERR_HTTP2_INVALID_SETTING_VALUE for invalid settings values.
1074 * Throws ERR_INVALID_ARG_TYPE for invalid settings argument.
1075 */
1076 updateSettings(settings: Settings): void;
1077 }
1078 export interface Http2Server extends net.Server, HTTP2ServerCommon {
1079 addListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1080 addListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1081 addListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1082 addListener(event: 'sessionError', listener: (err: Error) => void): this;
1083 addListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1084 addListener(event: 'timeout', listener: () => void): this;
1085 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1086 emit(event: 'checkContinue', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1087 emit(event: 'request', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1088 emit(event: 'session', session: ServerHttp2Session): boolean;
1089 emit(event: 'sessionError', err: Error): boolean;
1090 emit(event: 'stream', stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1091 emit(event: 'timeout'): boolean;
1092 emit(event: string | symbol, ...args: any[]): boolean;
1093 on(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1094 on(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1095 on(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1096 on(event: 'sessionError', listener: (err: Error) => void): this;
1097 on(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1098 on(event: 'timeout', listener: () => void): this;
1099 on(event: string | symbol, listener: (...args: any[]) => void): this;
1100 once(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1101 once(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1102 once(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1103 once(event: 'sessionError', listener: (err: Error) => void): this;
1104 once(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1105 once(event: 'timeout', listener: () => void): this;
1106 once(event: string | symbol, listener: (...args: any[]) => void): this;
1107 prependListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1108 prependListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1109 prependListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1110 prependListener(event: 'sessionError', listener: (err: Error) => void): this;
1111 prependListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1112 prependListener(event: 'timeout', listener: () => void): this;
1113 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1114 prependOnceListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1115 prependOnceListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1116 prependOnceListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1117 prependOnceListener(event: 'sessionError', listener: (err: Error) => void): this;
1118 prependOnceListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1119 prependOnceListener(event: 'timeout', listener: () => void): this;
1120 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1121 }
1122 export interface Http2SecureServer extends tls.Server, HTTP2ServerCommon {
1123 addListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1124 addListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1125 addListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1126 addListener(event: 'sessionError', listener: (err: Error) => void): this;
1127 addListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1128 addListener(event: 'timeout', listener: () => void): this;
1129 addListener(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
1130 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1131 emit(event: 'checkContinue', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1132 emit(event: 'request', request: Http2ServerRequest, response: Http2ServerResponse): boolean;
1133 emit(event: 'session', session: ServerHttp2Session): boolean;
1134 emit(event: 'sessionError', err: Error): boolean;
1135 emit(event: 'stream', stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
1136 emit(event: 'timeout'): boolean;
1137 emit(event: 'unknownProtocol', socket: tls.TLSSocket): boolean;
1138 emit(event: string | symbol, ...args: any[]): boolean;
1139 on(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1140 on(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1141 on(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1142 on(event: 'sessionError', listener: (err: Error) => void): this;
1143 on(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1144 on(event: 'timeout', listener: () => void): this;
1145 on(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
1146 on(event: string | symbol, listener: (...args: any[]) => void): this;
1147 once(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1148 once(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1149 once(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1150 once(event: 'sessionError', listener: (err: Error) => void): this;
1151 once(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1152 once(event: 'timeout', listener: () => void): this;
1153 once(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
1154 once(event: string | symbol, listener: (...args: any[]) => void): this;
1155 prependListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1156 prependListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1157 prependListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1158 prependListener(event: 'sessionError', listener: (err: Error) => void): this;
1159 prependListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1160 prependListener(event: 'timeout', listener: () => void): this;
1161 prependListener(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
1162 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1163 prependOnceListener(event: 'checkContinue', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1164 prependOnceListener(event: 'request', listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
1165 prependOnceListener(event: 'session', listener: (session: ServerHttp2Session) => void): this;
1166 prependOnceListener(event: 'sessionError', listener: (err: Error) => void): this;
1167 prependOnceListener(event: 'stream', listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1168 prependOnceListener(event: 'timeout', listener: () => void): this;
1169 prependOnceListener(event: 'unknownProtocol', listener: (socket: tls.TLSSocket) => void): this;
1170 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1171 }
1172 /**
1173 * 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,
1174 * headers, and
1175 * data.
1176 * @since v8.4.0
1177 */
1178 export class Http2ServerRequest extends stream.Readable {
1179 constructor(stream: ServerHttp2Stream, headers: IncomingHttpHeaders, options: stream.ReadableOptions, rawHeaders: ReadonlyArray<string>);
1180 /**
1181 * The `request.aborted` property will be `true` if the request has
1182 * been aborted.
1183 * @since v10.1.0
1184 */
1185 readonly aborted: boolean;
1186 /**
1187 * The request authority pseudo header field. Because HTTP/2 allows requests
1188 * to set either `:authority` or `host`, this value is derived from`req.headers[':authority']` if present. Otherwise, it is derived from`req.headers['host']`.
1189 * @since v8.4.0
1190 */
1191 readonly authority: string;
1192 /**
1193 * See `request.socket`.
1194 * @since v8.4.0
1195 * @deprecated Since v13.0.0 - Use `socket`.
1196 */
1197 readonly connection: net.Socket | tls.TLSSocket;
1198 /**
1199 * The `request.complete` property will be `true` if the request has
1200 * been completed, aborted, or destroyed.
1201 * @since v12.10.0
1202 */
1203 readonly complete: boolean;
1204 /**
1205 * The request/response headers object.
1206 *
1207 * Key-value pairs of header names and values. Header names are lower-cased.
1208 *
1209 * ```js
1210 * // Prints something like:
1211 * //
1212 * // { 'user-agent': 'curl/7.22.0',
1213 * // host: '127.0.0.1:8000',
1214 * // accept: '*' }
1215 * console.log(request.headers);
1216 * ```
1217 *
1218 * See `HTTP/2 Headers Object`.
1219 *
1220 * In HTTP/2, the request path, host name, protocol, and method are represented as
1221 * special headers prefixed with the `:` character (e.g. `':path'`). These special
1222 * headers will be included in the `request.headers` object. Care must be taken not
1223 * to inadvertently modify these special headers or errors may occur. For instance,
1224 * removing all headers from the request will cause errors to occur:
1225 *
1226 * ```js
1227 * removeAllHeaders(request.headers);
1228 * assert(request.url); // Fails because the :path header has been removed
1229 * ```
1230 * @since v8.4.0
1231 */
1232 readonly headers: IncomingHttpHeaders;
1233 /**
1234 * In case of server request, the HTTP version sent by the client. In the case of
1235 * client response, the HTTP version of the connected-to server. Returns`'2.0'`.
1236 *
1237 * Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
1238 * @since v8.4.0
1239 */
1240 readonly httpVersion: string;
1241 readonly httpVersionMinor: number;
1242 readonly httpVersionMajor: number;
1243 /**
1244 * The request method as a string. Read-only. Examples: `'GET'`, `'DELETE'`.
1245 * @since v8.4.0
1246 */
1247 readonly method: string;
1248 /**
1249 * The raw request/response headers list exactly as they were received.
1250 *
1251 * The keys and values are in the same list. It is _not_ a
1252 * list of tuples. So, the even-numbered offsets are key values, and the
1253 * odd-numbered offsets are the associated values.
1254 *
1255 * Header names are not lowercased, and duplicates are not merged.
1256 *
1257 * ```js
1258 * // Prints something like:
1259 * //
1260 * // [ 'user-agent',
1261 * // 'this is invalid because there can be only one',
1262 * // 'User-Agent',
1263 * // 'curl/7.22.0',
1264 * // 'Host',
1265 * // '127.0.0.1:8000',
1266 * // 'ACCEPT',
1267 * // '*' ]
1268 * console.log(request.rawHeaders);
1269 * ```
1270 * @since v8.4.0
1271 */
1272 readonly rawHeaders: string[];
1273 /**
1274 * The raw request/response trailer keys and values exactly as they were
1275 * received. Only populated at the `'end'` event.
1276 * @since v8.4.0
1277 */
1278 readonly rawTrailers: string[];
1279 /**
1280 * The request scheme pseudo header field indicating the scheme
1281 * portion of the target URL.
1282 * @since v8.4.0
1283 */
1284 readonly scheme: string;
1285 /**
1286 * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
1287 * applies getters, setters, and methods based on HTTP/2 logic.
1288 *
1289 * `destroyed`, `readable`, and `writable` properties will be retrieved from and
1290 * set on `request.stream`.
1291 *
1292 * `destroy`, `emit`, `end`, `on` and `once` methods will be called on`request.stream`.
1293 *
1294 * `setTimeout` method will be called on `request.stream.session`.
1295 *
1296 * `pause`, `read`, `resume`, and `write` will throw an error with code`ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for
1297 * more information.
1298 *
1299 * All other interactions will be routed directly to the socket. With TLS support,
1300 * use `request.socket.getPeerCertificate()` to obtain the client's
1301 * authentication details.
1302 * @since v8.4.0
1303 */
1304 readonly socket: net.Socket | tls.TLSSocket;
1305 /**
1306 * The `Http2Stream` object backing the request.
1307 * @since v8.4.0
1308 */
1309 readonly stream: ServerHttp2Stream;
1310 /**
1311 * The request/response trailers object. Only populated at the `'end'` event.
1312 * @since v8.4.0
1313 */
1314 readonly trailers: IncomingHttpHeaders;
1315 /**
1316 * Request URL string. This contains only the URL that is present in the actual
1317 * HTTP request. If the request is:
1318 *
1319 * ```http
1320 * GET /status?name=ryan HTTP/1.1
1321 * Accept: text/plain
1322 * ```
1323 *
1324 * Then `request.url` will be:
1325 *
1326 * ```js
1327 * '/status?name=ryan'
1328 * ```
1329 *
1330 * To parse the url into its parts, `new URL()` can be used:
1331 *
1332 * ```console
1333 * $ node
1334 * > new URL('/status?name=ryan', 'http://example.com')
1335 * URL {
1336 * href: 'http://example.com/status?name=ryan',
1337 * origin: 'http://example.com',
1338 * protocol: 'http:',
1339 * username: '',
1340 * password: '',
1341 * host: 'example.com',
1342 * hostname: 'example.com',
1343 * port: '',
1344 * pathname: '/status',
1345 * search: '?name=ryan',
1346 * searchParams: URLSearchParams { 'name' => 'ryan' },
1347 * hash: ''
1348 * }
1349 * ```
1350 * @since v8.4.0
1351 */
1352 readonly url: string;
1353 /**
1354 * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
1355 * provided, then it is added as a listener on the `'timeout'` event on
1356 * the response object.
1357 *
1358 * If no `'timeout'` listener is added to the request, the response, or
1359 * the server, then `Http2Stream` s are destroyed when they time out. If a
1360 * handler is assigned to the request, the response, or the server's `'timeout'`events, timed out sockets must be handled explicitly.
1361 * @since v8.4.0
1362 */
1363 setTimeout(msecs: number, callback?: () => void): void;
1364 read(size?: number): Buffer | string | null;
1365 addListener(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1366 addListener(event: 'close', listener: () => void): this;
1367 addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
1368 addListener(event: 'end', listener: () => void): this;
1369 addListener(event: 'readable', listener: () => void): this;
1370 addListener(event: 'error', listener: (err: Error) => void): this;
1371 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1372 emit(event: 'aborted', hadError: boolean, code: number): boolean;
1373 emit(event: 'close'): boolean;
1374 emit(event: 'data', chunk: Buffer | string): boolean;
1375 emit(event: 'end'): boolean;
1376 emit(event: 'readable'): boolean;
1377 emit(event: 'error', err: Error): boolean;
1378 emit(event: string | symbol, ...args: any[]): boolean;
1379 on(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1380 on(event: 'close', listener: () => void): this;
1381 on(event: 'data', listener: (chunk: Buffer | string) => void): this;
1382 on(event: 'end', listener: () => void): this;
1383 on(event: 'readable', listener: () => void): this;
1384 on(event: 'error', listener: (err: Error) => void): this;
1385 on(event: string | symbol, listener: (...args: any[]) => void): this;
1386 once(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1387 once(event: 'close', listener: () => void): this;
1388 once(event: 'data', listener: (chunk: Buffer | string) => void): this;
1389 once(event: 'end', listener: () => void): this;
1390 once(event: 'readable', listener: () => void): this;
1391 once(event: 'error', listener: (err: Error) => void): this;
1392 once(event: string | symbol, listener: (...args: any[]) => void): this;
1393 prependListener(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1394 prependListener(event: 'close', listener: () => void): this;
1395 prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
1396 prependListener(event: 'end', listener: () => void): this;
1397 prependListener(event: 'readable', listener: () => void): this;
1398 prependListener(event: 'error', listener: (err: Error) => void): this;
1399 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1400 prependOnceListener(event: 'aborted', listener: (hadError: boolean, code: number) => void): this;
1401 prependOnceListener(event: 'close', listener: () => void): this;
1402 prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
1403 prependOnceListener(event: 'end', listener: () => void): this;
1404 prependOnceListener(event: 'readable', listener: () => void): this;
1405 prependOnceListener(event: 'error', listener: (err: Error) => void): this;
1406 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1407 }
1408 /**
1409 * This object is created internally by an HTTP server, not by the user. It is
1410 * passed as the second parameter to the `'request'` event.
1411 * @since v8.4.0
1412 */
1413 export class Http2ServerResponse extends stream.Writable {
1414 constructor(stream: ServerHttp2Stream);
1415 /**
1416 * See `response.socket`.
1417 * @since v8.4.0
1418 * @deprecated Since v13.0.0 - Use `socket`.
1419 */
1420 readonly connection: net.Socket | tls.TLSSocket;
1421 /**
1422 * Boolean value that indicates whether the response has completed. Starts
1423 * as `false`. After `response.end()` executes, the value will be `true`.
1424 * @since v8.4.0
1425 * @deprecated Since v13.4.0,v12.16.0 - Use `writableEnded`.
1426 */
1427 readonly finished: boolean;
1428 /**
1429 * True if headers were sent, false otherwise (read-only).
1430 * @since v8.4.0
1431 */
1432 readonly headersSent: boolean;
1433 /**
1434 * A reference to the original HTTP2 request object.
1435 * @since v15.7.0
1436 */
1437 readonly req: Http2ServerRequest;
1438 /**
1439 * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
1440 * applies getters, setters, and methods based on HTTP/2 logic.
1441 *
1442 * `destroyed`, `readable`, and `writable` properties will be retrieved from and
1443 * set on `response.stream`.
1444 *
1445 * `destroy`, `emit`, `end`, `on` and `once` methods will be called on`response.stream`.
1446 *
1447 * `setTimeout` method will be called on `response.stream.session`.
1448 *
1449 * `pause`, `read`, `resume`, and `write` will throw an error with code`ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for
1450 * more information.
1451 *
1452 * All other interactions will be routed directly to the socket.
1453 *
1454 * ```js
1455 * const http2 = require('http2');
1456 * const server = http2.createServer((req, res) => {
1457 * const ip = req.socket.remoteAddress;
1458 * const port = req.socket.remotePort;
1459 * res.end(`Your IP address is ${ip} and your source port is ${port}.`);
1460 * }).listen(3000);
1461 * ```
1462 * @since v8.4.0
1463 */
1464 readonly socket: net.Socket | tls.TLSSocket;
1465 /**
1466 * The `Http2Stream` object backing the response.
1467 * @since v8.4.0
1468 */
1469 readonly stream: ServerHttp2Stream;
1470 /**
1471 * When true, the Date header will be automatically generated and sent in
1472 * the response if it is not already present in the headers. Defaults to true.
1473 *
1474 * This should only be disabled for testing; HTTP requires the Date header
1475 * in responses.
1476 * @since v8.4.0
1477 */
1478 sendDate: boolean;
1479 /**
1480 * When using implicit headers (not calling `response.writeHead()` explicitly),
1481 * this property controls the status code that will be sent to the client when
1482 * the headers get flushed.
1483 *
1484 * ```js
1485 * response.statusCode = 404;
1486 * ```
1487 *
1488 * After response header was sent to the client, this property indicates the
1489 * status code which was sent out.
1490 * @since v8.4.0
1491 */
1492 statusCode: number;
1493 /**
1494 * Status message is not supported by HTTP/2 (RFC 7540 8.1.2.4). It returns
1495 * an empty string.
1496 * @since v8.4.0
1497 */
1498 statusMessage: '';
1499 /**
1500 * This method adds HTTP trailing headers (a header but at the end of the
1501 * message) to the response.
1502 *
1503 * Attempting to set a header field name or value that contains invalid characters
1504 * will result in a `TypeError` being thrown.
1505 * @since v8.4.0
1506 */
1507 addTrailers(trailers: OutgoingHttpHeaders): void;
1508 /**
1509 * This method signals to the server that all of the response headers and body
1510 * have been sent; that server should consider this message complete.
1511 * The method, `response.end()`, MUST be called on each response.
1512 *
1513 * If `data` is specified, it is equivalent to calling `response.write(data, encoding)` followed by `response.end(callback)`.
1514 *
1515 * If `callback` is specified, it will be called when the response stream
1516 * is finished.
1517 * @since v8.4.0
1518 */
1519 end(callback?: () => void): void;
1520 end(data: string | Uint8Array, callback?: () => void): void;
1521 end(data: string | Uint8Array, encoding: BufferEncoding, callback?: () => void): void;
1522 /**
1523 * Reads out a header that has already been queued but not sent to the client.
1524 * The name is case-insensitive.
1525 *
1526 * ```js
1527 * const contentType = response.getHeader('content-type');
1528 * ```
1529 * @since v8.4.0
1530 */
1531 getHeader(name: string): string;
1532 /**
1533 * Returns an array containing the unique names of the current outgoing headers.
1534 * All header names are lowercase.
1535 *
1536 * ```js
1537 * response.setHeader('Foo', 'bar');
1538 * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
1539 *
1540 * const headerNames = response.getHeaderNames();
1541 * // headerNames === ['foo', 'set-cookie']
1542 * ```
1543 * @since v8.4.0
1544 */
1545 getHeaderNames(): string[];
1546 /**
1547 * Returns a shallow copy of the current outgoing headers. Since a shallow copy
1548 * is used, array values may be mutated without additional calls to various
1549 * header-related http module methods. The keys of the returned object are the
1550 * header names and the values are the respective header values. All header names
1551 * are lowercase.
1552 *
1553 * 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()`,
1554 * `obj.hasOwnProperty()`, and others
1555 * are not defined and _will not work_.
1556 *
1557 * ```js
1558 * response.setHeader('Foo', 'bar');
1559 * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
1560 *
1561 * const headers = response.getHeaders();
1562 * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
1563 * ```
1564 * @since v8.4.0
1565 */
1566 getHeaders(): OutgoingHttpHeaders;
1567 /**
1568 * Returns `true` if the header identified by `name` is currently set in the
1569 * outgoing headers. The header name matching is case-insensitive.
1570 *
1571 * ```js
1572 * const hasContentType = response.hasHeader('content-type');
1573 * ```
1574 * @since v8.4.0
1575 */
1576 hasHeader(name: string): boolean;
1577 /**
1578 * Removes a header that has been queued for implicit sending.
1579 *
1580 * ```js
1581 * response.removeHeader('Content-Encoding');
1582 * ```
1583 * @since v8.4.0
1584 */
1585 removeHeader(name: string): void;
1586 /**
1587 * Sets a single header value for implicit headers. If this header already exists
1588 * in the to-be-sent headers, its value will be replaced. Use an array of strings
1589 * here to send multiple headers with the same name.
1590 *
1591 * ```js
1592 * response.setHeader('Content-Type', 'text/html; charset=utf-8');
1593 * ```
1594 *
1595 * or
1596 *
1597 * ```js
1598 * response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
1599 * ```
1600 *
1601 * Attempting to set a header field name or value that contains invalid characters
1602 * will result in a `TypeError` being thrown.
1603 *
1604 * When headers have been set with `response.setHeader()`, they will be merged
1605 * with any headers passed to `response.writeHead()`, with the headers passed
1606 * to `response.writeHead()` given precedence.
1607 *
1608 * ```js
1609 * // Returns content-type = text/plain
1610 * const server = http2.createServer((req, res) => {
1611 * res.setHeader('Content-Type', 'text/html; charset=utf-8');
1612 * res.setHeader('X-Foo', 'bar');
1613 * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
1614 * res.end('ok');
1615 * });
1616 * ```
1617 * @since v8.4.0
1618 */
1619 setHeader(name: string, value: number | string | ReadonlyArray<string>): void;
1620 /**
1621 * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
1622 * provided, then it is added as a listener on the `'timeout'` event on
1623 * the response object.
1624 *
1625 * If no `'timeout'` listener is added to the request, the response, or
1626 * the server, then `Http2Stream` s are destroyed when they time out. If a
1627 * handler is assigned to the request, the response, or the server's `'timeout'`events, timed out sockets must be handled explicitly.
1628 * @since v8.4.0
1629 */
1630 setTimeout(msecs: number, callback?: () => void): void;
1631 /**
1632 * If this method is called and `response.writeHead()` has not been called,
1633 * it will switch to implicit header mode and flush the implicit headers.
1634 *
1635 * This sends a chunk of the response body. This method may
1636 * be called multiple times to provide successive parts of the body.
1637 *
1638 * In the `http` module, the response body is omitted when the
1639 * request is a HEAD request. Similarly, the `204` and `304` responses_must not_ include a message body.
1640 *
1641 * `chunk` can be a string or a buffer. If `chunk` is a string,
1642 * the second parameter specifies how to encode it into a byte stream.
1643 * By default the `encoding` is `'utf8'`. `callback` will be called when this chunk
1644 * of data is flushed.
1645 *
1646 * This is the raw HTTP body and has nothing to do with higher-level multi-part
1647 * body encodings that may be used.
1648 *
1649 * The first time `response.write()` is called, it will send the buffered
1650 * header information and the first chunk of the body to the client. The second
1651 * time `response.write()` is called, Node.js assumes data will be streamed,
1652 * and sends the new data separately. That is, the response is buffered up to the
1653 * first chunk of the body.
1654 *
1655 * Returns `true` if the entire data was flushed successfully to the kernel
1656 * 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.
1657 * @since v8.4.0
1658 */
1659 write(chunk: string | Uint8Array, callback?: (err: Error) => void): boolean;
1660 write(chunk: string | Uint8Array, encoding: BufferEncoding, callback?: (err: Error) => void): boolean;
1661 /**
1662 * Sends a status `100 Continue` to the client, indicating that the request body
1663 * should be sent. See the `'checkContinue'` event on `Http2Server` and`Http2SecureServer`.
1664 * @since v8.4.0
1665 */
1666 writeContinue(): void;
1667 /**
1668 * Sends a response header to the request. The status code is a 3-digit HTTP
1669 * status code, like `404`. The last argument, `headers`, are the response headers.
1670 *
1671 * Returns a reference to the `Http2ServerResponse`, so that calls can be chained.
1672 *
1673 * For compatibility with `HTTP/1`, a human-readable `statusMessage` may be
1674 * passed as the second argument. However, because the `statusMessage` has no
1675 * meaning within HTTP/2, the argument will have no effect and a process warning
1676 * will be emitted.
1677 *
1678 * ```js
1679 * const body = 'hello world';
1680 * response.writeHead(200, {
1681 * 'Content-Length': Buffer.byteLength(body),
1682 * 'Content-Type': 'text/plain; charset=utf-8',
1683 * });
1684 * ```
1685 *
1686 * `Content-Length` is given in bytes not characters. The`Buffer.byteLength()` API may be used to determine the number of bytes in a
1687 * given encoding. On outbound messages, Node.js does not check if Content-Length
1688 * and the length of the body being transmitted are equal or not. However, when
1689 * receiving messages, Node.js will automatically reject messages when the`Content-Length` does not match the actual payload size.
1690 *
1691 * This method may be called at most one time on a message before `response.end()` is called.
1692 *
1693 * If `response.write()` or `response.end()` are called before calling
1694 * this, the implicit/mutable headers will be calculated and call this function.
1695 *
1696 * When headers have been set with `response.setHeader()`, they will be merged
1697 * with any headers passed to `response.writeHead()`, with the headers passed
1698 * to `response.writeHead()` given precedence.
1699 *
1700 * ```js
1701 * // Returns content-type = text/plain
1702 * const server = http2.createServer((req, res) => {
1703 * res.setHeader('Content-Type', 'text/html; charset=utf-8');
1704 * res.setHeader('X-Foo', 'bar');
1705 * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
1706 * res.end('ok');
1707 * });
1708 * ```
1709 *
1710 * Attempting to set a header field name or value that contains invalid characters
1711 * will result in a `TypeError` being thrown.
1712 * @since v8.4.0
1713 */
1714 writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this;
1715 writeHead(statusCode: number, statusMessage: string, headers?: OutgoingHttpHeaders): this;
1716 /**
1717 * Call `http2stream.pushStream()` with the given headers, and wrap the
1718 * given `Http2Stream` on a newly created `Http2ServerResponse` as the callback
1719 * parameter if successful. When `Http2ServerRequest` is closed, the callback is
1720 * called with an error `ERR_HTTP2_INVALID_STREAM`.
1721 * @since v8.4.0
1722 * @param headers An object describing the headers
1723 * @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
1724 * `Http2ServerRequest` is closed prior to calling the `http2stream.pushStream()` method
1725 */
1726 createPushResponse(headers: OutgoingHttpHeaders, callback: (err: Error | null, res: Http2ServerResponse) => void): void;
1727 addListener(event: 'close', listener: () => void): this;
1728 addListener(event: 'drain', listener: () => void): this;
1729 addListener(event: 'error', listener: (error: Error) => void): this;
1730 addListener(event: 'finish', listener: () => void): this;
1731 addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
1732 addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
1733 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1734 emit(event: 'close'): boolean;
1735 emit(event: 'drain'): boolean;
1736 emit(event: 'error', error: Error): boolean;
1737 emit(event: 'finish'): boolean;
1738 emit(event: 'pipe', src: stream.Readable): boolean;
1739 emit(event: 'unpipe', src: stream.Readable): boolean;
1740 emit(event: string | symbol, ...args: any[]): boolean;
1741 on(event: 'close', listener: () => void): this;
1742 on(event: 'drain', listener: () => void): this;
1743 on(event: 'error', listener: (error: Error) => void): this;
1744 on(event: 'finish', listener: () => void): this;
1745 on(event: 'pipe', listener: (src: stream.Readable) => void): this;
1746 on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
1747 on(event: string | symbol, listener: (...args: any[]) => void): this;
1748 once(event: 'close', listener: () => void): this;
1749 once(event: 'drain', listener: () => void): this;
1750 once(event: 'error', listener: (error: Error) => void): this;
1751 once(event: 'finish', listener: () => void): this;
1752 once(event: 'pipe', listener: (src: stream.Readable) => void): this;
1753 once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
1754 once(event: string | symbol, listener: (...args: any[]) => void): this;
1755 prependListener(event: 'close', listener: () => void): this;
1756 prependListener(event: 'drain', listener: () => void): this;
1757 prependListener(event: 'error', listener: (error: Error) => void): this;
1758 prependListener(event: 'finish', listener: () => void): this;
1759 prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
1760 prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
1761 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1762 prependOnceListener(event: 'close', listener: () => void): this;
1763 prependOnceListener(event: 'drain', listener: () => void): this;
1764 prependOnceListener(event: 'error', listener: (error: Error) => void): this;
1765 prependOnceListener(event: 'finish', listener: () => void): this;
1766 prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
1767 prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
1768 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1769 }
1770 export namespace constants {
1771 const NGHTTP2_SESSION_SERVER: number;
1772 const NGHTTP2_SESSION_CLIENT: number;
1773 const NGHTTP2_STREAM_STATE_IDLE: number;
1774 const NGHTTP2_STREAM_STATE_OPEN: number;
1775 const NGHTTP2_STREAM_STATE_RESERVED_LOCAL: number;
1776 const NGHTTP2_STREAM_STATE_RESERVED_REMOTE: number;
1777 const NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL: number;
1778 const NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE: number;
1779 const NGHTTP2_STREAM_STATE_CLOSED: number;
1780 const NGHTTP2_NO_ERROR: number;
1781 const NGHTTP2_PROTOCOL_ERROR: number;
1782 const NGHTTP2_INTERNAL_ERROR: number;
1783 const NGHTTP2_FLOW_CONTROL_ERROR: number;
1784 const NGHTTP2_SETTINGS_TIMEOUT: number;
1785 const NGHTTP2_STREAM_CLOSED: number;
1786 const NGHTTP2_FRAME_SIZE_ERROR: number;
1787 const NGHTTP2_REFUSED_STREAM: number;
1788 const NGHTTP2_CANCEL: number;
1789 const NGHTTP2_COMPRESSION_ERROR: number;
1790 const NGHTTP2_CONNECT_ERROR: number;
1791 const NGHTTP2_ENHANCE_YOUR_CALM: number;
1792 const NGHTTP2_INADEQUATE_SECURITY: number;
1793 const NGHTTP2_HTTP_1_1_REQUIRED: number;
1794 const NGHTTP2_ERR_FRAME_SIZE_ERROR: number;
1795 const NGHTTP2_FLAG_NONE: number;
1796 const NGHTTP2_FLAG_END_STREAM: number;
1797 const NGHTTP2_FLAG_END_HEADERS: number;
1798 const NGHTTP2_FLAG_ACK: number;
1799 const NGHTTP2_FLAG_PADDED: number;
1800 const NGHTTP2_FLAG_PRIORITY: number;
1801 const DEFAULT_SETTINGS_HEADER_TABLE_SIZE: number;
1802 const DEFAULT_SETTINGS_ENABLE_PUSH: number;
1803 const DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: number;
1804 const DEFAULT_SETTINGS_MAX_FRAME_SIZE: number;
1805 const MAX_MAX_FRAME_SIZE: number;
1806 const MIN_MAX_FRAME_SIZE: number;
1807 const MAX_INITIAL_WINDOW_SIZE: number;
1808 const NGHTTP2_DEFAULT_WEIGHT: number;
1809 const NGHTTP2_SETTINGS_HEADER_TABLE_SIZE: number;
1810 const NGHTTP2_SETTINGS_ENABLE_PUSH: number;
1811 const NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS: number;
1812 const NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE: number;
1813 const NGHTTP2_SETTINGS_MAX_FRAME_SIZE: number;
1814 const NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE: number;
1815 const PADDING_STRATEGY_NONE: number;
1816 const PADDING_STRATEGY_MAX: number;
1817 const PADDING_STRATEGY_CALLBACK: number;
1818 const HTTP2_HEADER_STATUS: string;
1819 const HTTP2_HEADER_METHOD: string;
1820 const HTTP2_HEADER_AUTHORITY: string;
1821 const HTTP2_HEADER_SCHEME: string;
1822 const HTTP2_HEADER_PATH: string;
1823 const HTTP2_HEADER_ACCEPT_CHARSET: string;
1824 const HTTP2_HEADER_ACCEPT_ENCODING: string;
1825 const HTTP2_HEADER_ACCEPT_LANGUAGE: string;
1826 const HTTP2_HEADER_ACCEPT_RANGES: string;
1827 const HTTP2_HEADER_ACCEPT: string;
1828 const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN: string;
1829 const HTTP2_HEADER_AGE: string;
1830 const HTTP2_HEADER_ALLOW: string;
1831 const HTTP2_HEADER_AUTHORIZATION: string;
1832 const HTTP2_HEADER_CACHE_CONTROL: string;
1833 const HTTP2_HEADER_CONNECTION: string;
1834 const HTTP2_HEADER_CONTENT_DISPOSITION: string;
1835 const HTTP2_HEADER_CONTENT_ENCODING: string;
1836 const HTTP2_HEADER_CONTENT_LANGUAGE: string;
1837 const HTTP2_HEADER_CONTENT_LENGTH: string;
1838 const HTTP2_HEADER_CONTENT_LOCATION: string;
1839 const HTTP2_HEADER_CONTENT_MD5: string;
1840 const HTTP2_HEADER_CONTENT_RANGE: string;
1841 const HTTP2_HEADER_CONTENT_TYPE: string;
1842 const HTTP2_HEADER_COOKIE: string;
1843 const HTTP2_HEADER_DATE: string;
1844 const HTTP2_HEADER_ETAG: string;
1845 const HTTP2_HEADER_EXPECT: string;
1846 const HTTP2_HEADER_EXPIRES: string;
1847 const HTTP2_HEADER_FROM: string;
1848 const HTTP2_HEADER_HOST: string;
1849 const HTTP2_HEADER_IF_MATCH: string;
1850 const HTTP2_HEADER_IF_MODIFIED_SINCE: string;
1851 const HTTP2_HEADER_IF_NONE_MATCH: string;
1852 const HTTP2_HEADER_IF_RANGE: string;
1853 const HTTP2_HEADER_IF_UNMODIFIED_SINCE: string;
1854 const HTTP2_HEADER_LAST_MODIFIED: string;
1855 const HTTP2_HEADER_LINK: string;
1856 const HTTP2_HEADER_LOCATION: string;
1857 const HTTP2_HEADER_MAX_FORWARDS: string;
1858 const HTTP2_HEADER_PREFER: string;
1859 const HTTP2_HEADER_PROXY_AUTHENTICATE: string;
1860 const HTTP2_HEADER_PROXY_AUTHORIZATION: string;
1861 const HTTP2_HEADER_RANGE: string;
1862 const HTTP2_HEADER_REFERER: string;
1863 const HTTP2_HEADER_REFRESH: string;
1864 const HTTP2_HEADER_RETRY_AFTER: string;
1865 const HTTP2_HEADER_SERVER: string;
1866 const HTTP2_HEADER_SET_COOKIE: string;
1867 const HTTP2_HEADER_STRICT_TRANSPORT_SECURITY: string;
1868 const HTTP2_HEADER_TRANSFER_ENCODING: string;
1869 const HTTP2_HEADER_TE: string;
1870 const HTTP2_HEADER_UPGRADE: string;
1871 const HTTP2_HEADER_USER_AGENT: string;
1872 const HTTP2_HEADER_VARY: string;
1873 const HTTP2_HEADER_VIA: string;
1874 const HTTP2_HEADER_WWW_AUTHENTICATE: string;
1875 const HTTP2_HEADER_HTTP2_SETTINGS: string;
1876 const HTTP2_HEADER_KEEP_ALIVE: string;
1877 const HTTP2_HEADER_PROXY_CONNECTION: string;
1878 const HTTP2_METHOD_ACL: string;
1879 const HTTP2_METHOD_BASELINE_CONTROL: string;
1880 const HTTP2_METHOD_BIND: string;
1881 const HTTP2_METHOD_CHECKIN: string;
1882 const HTTP2_METHOD_CHECKOUT: string;
1883 const HTTP2_METHOD_CONNECT: string;
1884 const HTTP2_METHOD_COPY: string;
1885 const HTTP2_METHOD_DELETE: string;
1886 const HTTP2_METHOD_GET: string;
1887 const HTTP2_METHOD_HEAD: string;
1888 const HTTP2_METHOD_LABEL: string;
1889 const HTTP2_METHOD_LINK: string;
1890 const HTTP2_METHOD_LOCK: string;
1891 const HTTP2_METHOD_MERGE: string;
1892 const HTTP2_METHOD_MKACTIVITY: string;
1893 const HTTP2_METHOD_MKCALENDAR: string;
1894 const HTTP2_METHOD_MKCOL: string;
1895 const HTTP2_METHOD_MKREDIRECTREF: string;
1896 const HTTP2_METHOD_MKWORKSPACE: string;
1897 const HTTP2_METHOD_MOVE: string;
1898 const HTTP2_METHOD_OPTIONS: string;
1899 const HTTP2_METHOD_ORDERPATCH: string;
1900 const HTTP2_METHOD_PATCH: string;
1901 const HTTP2_METHOD_POST: string;
1902 const HTTP2_METHOD_PRI: string;
1903 const HTTP2_METHOD_PROPFIND: string;
1904 const HTTP2_METHOD_PROPPATCH: string;
1905 const HTTP2_METHOD_PUT: string;
1906 const HTTP2_METHOD_REBIND: string;
1907 const HTTP2_METHOD_REPORT: string;
1908 const HTTP2_METHOD_SEARCH: string;
1909 const HTTP2_METHOD_TRACE: string;
1910 const HTTP2_METHOD_UNBIND: string;
1911 const HTTP2_METHOD_UNCHECKOUT: string;
1912 const HTTP2_METHOD_UNLINK: string;
1913 const HTTP2_METHOD_UNLOCK: string;
1914 const HTTP2_METHOD_UPDATE: string;
1915 const HTTP2_METHOD_UPDATEREDIRECTREF: string;
1916 const HTTP2_METHOD_VERSION_CONTROL: string;
1917 const HTTP_STATUS_CONTINUE: number;
1918 const HTTP_STATUS_SWITCHING_PROTOCOLS: number;
1919 const HTTP_STATUS_PROCESSING: number;
1920 const HTTP_STATUS_OK: number;
1921 const HTTP_STATUS_CREATED: number;
1922 const HTTP_STATUS_ACCEPTED: number;
1923 const HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION: number;
1924 const HTTP_STATUS_NO_CONTENT: number;
1925 const HTTP_STATUS_RESET_CONTENT: number;
1926 const HTTP_STATUS_PARTIAL_CONTENT: number;
1927 const HTTP_STATUS_MULTI_STATUS: number;
1928 const HTTP_STATUS_ALREADY_REPORTED: number;
1929 const HTTP_STATUS_IM_USED: number;
1930 const HTTP_STATUS_MULTIPLE_CHOICES: number;
1931 const HTTP_STATUS_MOVED_PERMANENTLY: number;
1932 const HTTP_STATUS_FOUND: number;
1933 const HTTP_STATUS_SEE_OTHER: number;
1934 const HTTP_STATUS_NOT_MODIFIED: number;
1935 const HTTP_STATUS_USE_PROXY: number;
1936 const HTTP_STATUS_TEMPORARY_REDIRECT: number;
1937 const HTTP_STATUS_PERMANENT_REDIRECT: number;
1938 const HTTP_STATUS_BAD_REQUEST: number;
1939 const HTTP_STATUS_UNAUTHORIZED: number;
1940 const HTTP_STATUS_PAYMENT_REQUIRED: number;
1941 const HTTP_STATUS_FORBIDDEN: number;
1942 const HTTP_STATUS_NOT_FOUND: number;
1943 const HTTP_STATUS_METHOD_NOT_ALLOWED: number;
1944 const HTTP_STATUS_NOT_ACCEPTABLE: number;
1945 const HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED: number;
1946 const HTTP_STATUS_REQUEST_TIMEOUT: number;
1947 const HTTP_STATUS_CONFLICT: number;
1948 const HTTP_STATUS_GONE: number;
1949 const HTTP_STATUS_LENGTH_REQUIRED: number;
1950 const HTTP_STATUS_PRECONDITION_FAILED: number;
1951 const HTTP_STATUS_PAYLOAD_TOO_LARGE: number;
1952 const HTTP_STATUS_URI_TOO_LONG: number;
1953 const HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE: number;
1954 const HTTP_STATUS_RANGE_NOT_SATISFIABLE: number;
1955 const HTTP_STATUS_EXPECTATION_FAILED: number;
1956 const HTTP_STATUS_TEAPOT: number;
1957 const HTTP_STATUS_MISDIRECTED_REQUEST: number;
1958 const HTTP_STATUS_UNPROCESSABLE_ENTITY: number;
1959 const HTTP_STATUS_LOCKED: number;
1960 const HTTP_STATUS_FAILED_DEPENDENCY: number;
1961 const HTTP_STATUS_UNORDERED_COLLECTION: number;
1962 const HTTP_STATUS_UPGRADE_REQUIRED: number;
1963 const HTTP_STATUS_PRECONDITION_REQUIRED: number;
1964 const HTTP_STATUS_TOO_MANY_REQUESTS: number;
1965 const HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE: number;
1966 const HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS: number;
1967 const HTTP_STATUS_INTERNAL_SERVER_ERROR: number;
1968 const HTTP_STATUS_NOT_IMPLEMENTED: number;
1969 const HTTP_STATUS_BAD_GATEWAY: number;
1970 const HTTP_STATUS_SERVICE_UNAVAILABLE: number;
1971 const HTTP_STATUS_GATEWAY_TIMEOUT: number;
1972 const HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED: number;
1973 const HTTP_STATUS_VARIANT_ALSO_NEGOTIATES: number;
1974 const HTTP_STATUS_INSUFFICIENT_STORAGE: number;
1975 const HTTP_STATUS_LOOP_DETECTED: number;
1976 const HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED: number;
1977 const HTTP_STATUS_NOT_EXTENDED: number;
1978 const HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED: number;
1979 }
1980 /**
1981 * This symbol can be set as a property on the HTTP/2 headers object with
1982 * an array value in order to provide a list of headers considered sensitive.
1983 */
1984 export const sensitiveHeaders: symbol;
1985 /**
1986 * Returns an object containing the default settings for an `Http2Session`instance. This method returns a new object instance every time it is called
1987 * so instances returned may be safely modified for use.
1988 * @since v8.4.0
1989 */
1990 export function getDefaultSettings(): Settings;
1991 /**
1992 * Returns a `Buffer` instance containing serialized representation of the given
1993 * HTTP/2 settings as specified in the [HTTP/2](https://tools.ietf.org/html/rfc7540) specification. This is intended
1994 * for use with the `HTTP2-Settings` header field.
1995 *
1996 * ```js
1997 * const http2 = require('http2');
1998 *
1999 * const packed = http2.getPackedSettings({ enablePush: false });
2000 *
2001 * console.log(packed.toString('base64'));
2002 * // Prints: AAIAAAAA
2003 * ```
2004 * @since v8.4.0
2005 */
2006 export function getPackedSettings(settings: Settings): Buffer;
2007 /**
2008 * Returns a `HTTP/2 Settings Object` containing the deserialized settings from
2009 * the given `Buffer` as generated by `http2.getPackedSettings()`.
2010 * @since v8.4.0
2011 * @param buf The packed settings.
2012 */
2013 export function getUnpackedSettings(buf: Uint8Array): Settings;
2014 /**
2015 * Returns a `net.Server` instance that creates and manages `Http2Session`instances.
2016 *
2017 * 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
2018 * communicating
2019 * with browser clients.
2020 *
2021 * ```js
2022 * const http2 = require('http2');
2023 *
2024 * // Create an unencrypted HTTP/2 server.
2025 * // Since there are no browsers known that support
2026 * // unencrypted HTTP/2, the use of `http2.createSecureServer()`
2027 * // is necessary when communicating with browser clients.
2028 * const server = http2.createServer();
2029 *
2030 * server.on('stream', (stream, headers) => {
2031 * stream.respond({
2032 * 'content-type': 'text/html; charset=utf-8',
2033 * ':status': 200
2034 * });
2035 * stream.end('<h1>Hello World</h1>');
2036 * });
2037 *
2038 * server.listen(80);
2039 * ```
2040 * @since v8.4.0
2041 * @param onRequestHandler See `Compatibility API`
2042 */
2043 export function createServer(onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2Server;
2044 export function createServer(options: ServerOptions, onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2Server;
2045 /**
2046 * Returns a `tls.Server` instance that creates and manages `Http2Session`instances.
2047 *
2048 * ```js
2049 * const http2 = require('http2');
2050 * const fs = require('fs');
2051 *
2052 * const options = {
2053 * key: fs.readFileSync('server-key.pem'),
2054 * cert: fs.readFileSync('server-cert.pem')
2055 * };
2056 *
2057 * // Create a secure HTTP/2 server
2058 * const server = http2.createSecureServer(options);
2059 *
2060 * server.on('stream', (stream, headers) => {
2061 * stream.respond({
2062 * 'content-type': 'text/html; charset=utf-8',
2063 * ':status': 200
2064 * });
2065 * stream.end('<h1>Hello World</h1>');
2066 * });
2067 *
2068 * server.listen(80);
2069 * ```
2070 * @since v8.4.0
2071 * @param onRequestHandler See `Compatibility API`
2072 */
2073 export function createSecureServer(onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2SecureServer;
2074 export function createSecureServer(options: SecureServerOptions, onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2SecureServer;
2075 /**
2076 * Returns a `ClientHttp2Session` instance.
2077 *
2078 * ```js
2079 * const http2 = require('http2');
2080 * const client = http2.connect('https://localhost:1234');
2081 *
2082 * // Use the client
2083 *
2084 * client.close();
2085 * ```
2086 * @since v8.4.0
2087 * @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
2088 * is used). Userinfo (user ID and password), path, querystring, and fragment details in the URL will be ignored.
2089 * @param listener Will be registered as a one-time listener of the {@link 'connect'} event.
2090 */
2091 export function connect(authority: string | url.URL, listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): ClientHttp2Session;
2092 export function connect(
2093 authority: string | url.URL,
2094 options?: ClientSessionOptions | SecureClientSessionOptions,
2095 listener?: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void
2096 ): ClientHttp2Session;
2097}
2098declare module 'node:http2' {
2099 export * from 'http2';
2100}
2101
\No newline at end of file