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