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