Lines Matching +full:code +full:-
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width">
6 <meta name="nodejs.org:node-version" content="v18.20.1">
15 <body class="alt apidoc" id="api-section-http2">
24 <li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
25 <li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
29 <li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
30 <li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
31 <li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
32 <li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
33 <li><a href="addons.html" class="nav-addons">C++ addons</a></li>
34 <li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
35 <li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
36 <li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
37 <li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
38 <li><a href="cli.html" class="nav-cli">Command-line options</a></li>
39 <li><a href="console.html" class="nav-console">Console</a></li>
40 <li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
41 <li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
42 <li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
43 <li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
44 <li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
45 <li><a href="dns.html" class="nav-dns">DNS</a></li>
46 <li><a href="domain.html" class="nav-domain">Domain</a></li>
47 <li><a href="errors.html" class="nav-errors">Errors</a></li>
48 <li><a href="events.html" class="nav-events">Events</a></li>
49 <li><a href="fs.html" class="nav-fs">File system</a></li>
50 <li><a href="globals.html" class="nav-globals">Globals</a></li>
51 <li><a href="http.html" class="nav-http">HTTP</a></li>
52 <li><a href="http2.html" class="nav-http2 active">HTTP/2</a></li>
53 <li><a href="https.html" class="nav-https">HTTPS</a></li>
54 <li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
55 <li><a href="intl.html" class="nav-intl">Internationalization</a></li>
56 <li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
57 <li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
58 <li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
59 <li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
60 <li><a href="net.html" class="nav-net">Net</a></li>
61 <li><a href="os.html" class="nav-os">OS</a></li>
62 <li><a href="path.html" class="nav-path">Path</a></li>
63 <li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
64 <li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
65 <li><a href="process.html" class="nav-process">Process</a></li>
66 <li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
67 <li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
68 <li><a href="readline.html" class="nav-readline">Readline</a></li>
69 <li><a href="repl.html" class="nav-repl">REPL</a></li>
70 <li><a href="report.html" class="nav-report">Report</a></li>
71 <li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single…
72 <li><a href="stream.html" class="nav-stream">Stream</a></li>
73 <li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
74 <li><a href="test.html" class="nav-test">Test runner</a></li>
75 <li><a href="timers.html" class="nav-timers">Timers</a></li>
76 <li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
77 <li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
78 <li><a href="tty.html" class="nav-tty">TTY</a></li>
79 <li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
80 <li><a href="url.html" class="nav-url">URL</a></li>
81 <li><a href="util.html" class="nav-util">Utilities</a></li>
82 <li><a href="v8.html" class="nav-v8">V8</a></li>
83 <li><a href="vm.html" class="nav-vm">VM</a></li>
84 <li><a href="wasi.html" class="nav-wasi">WASI</a></li>
85 <li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
86 <li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
87 <li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
88 <li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
92 <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code reposito…
96 <div id="column1" data-id="http2" class="interior">
98 <div class="header-container">
100 …<button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-la…
101 <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
103 …-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.6…
104 …<path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2…
106 <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
108 …-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.4…
114 <li class="pinned-header">Node.js v18.20.1</li>
116 <li class="picker-header">
118 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
125 <li><a href="#determining-if-crypto-support-is-unavailable">Determining if crypto support is unavai…
126 <li><a href="#core-api">Core API</a>
128 <li><a href="#server-side-example">Server-side example</a></li>
129 <li><a href="#client-side-example">Client-side example</a></li>
130 <li><a href="#class-http2session">Class: <code>Http2Session</code></a>
132 <li><a href="#http2session-and-sockets"><code>Http2Session</code> and sockets</a></li>
133 <li><a href="#event-close">Event: <code>'close'</code></a></li>
134 <li><a href="#event-connect">Event: <code>'connect'</code></a></li>
135 <li><a href="#event-error">Event: <code>'error'</code></a></li>
136 <li><a href="#event-frameerror">Event: <code>'frameError'</code></a></li>
137 <li><a href="#event-goaway">Event: <code>'goaway'</code></a></li>
138 <li><a href="#event-localsettings">Event: <code>'localSettings'</code></a></li>
139 <li><a href="#event-ping">Event: <code>'ping'</code></a></li>
140 <li><a href="#event-remotesettings">Event: <code>'remoteSettings'</code></a></li>
141 <li><a href="#event-stream">Event: <code>'stream'</code></a></li>
142 <li><a href="#event-timeout">Event: <code>'timeout'</code></a></li>
143 <li><a href="#http2sessionalpnprotocol"><code>http2session.alpnProtocol</code></a></li>
144 <li><a href="#http2sessionclosecallback"><code>http2session.close([callback])</code></a></li>
145 <li><a href="#http2sessionclosed"><code>http2session.closed</code></a></li>
146 <li><a href="#http2sessionconnecting"><code>http2session.connecting</code></a></li>
147 <li><a href="#http2sessiondestroyerror-code"><code>http2session.destroy([error][, code])</code></a>…
148 <li><a href="#http2sessiondestroyed"><code>http2session.destroyed</code></a></li>
149 <li><a href="#http2sessionencrypted"><code>http2session.encrypted</code></a></li>
150 …href="#http2sessiongoawaycode-laststreamid-opaquedata"><code>http2session.goaway([code[, lastStrea…
151 <li><a href="#http2sessionlocalsettings"><code>http2session.localSettings</code></a></li>
152 <li><a href="#http2sessionoriginset"><code>http2session.originSet</code></a></li>
153 <li><a href="#http2sessionpendingsettingsack"><code>http2session.pendingSettingsAck</code></a></li>
154 <li><a href="#http2sessionpingpayload-callback"><code>http2session.ping([payload, ]callback)</code>…
155 <li><a href="#http2sessionref"><code>http2session.ref()</code></a></li>
156 <li><a href="#http2sessionremotesettings"><code>http2session.remoteSettings</code></a></li>
157 …ref="#http2sessionsetlocalwindowsizewindowsize"><code>http2session.setLocalWindowSize(windowSize)<…
158 <li><a href="#http2sessionsettimeoutmsecs-callback"><code>http2session.setTimeout(msecs, callback)<…
159 <li><a href="#http2sessionsocket"><code>http2session.socket</code></a></li>
160 <li><a href="#http2sessionstate"><code>http2session.state</code></a></li>
161 <li><a href="#http2sessionsettingssettings-callback"><code>http2session.settings([settings][, callb…
162 <li><a href="#http2sessiontype"><code>http2session.type</code></a></li>
163 <li><a href="#http2sessionunref"><code>http2session.unref()</code></a></li>
166 <li><a href="#class-serverhttp2session">Class: <code>ServerHttp2Session</code></a>
168 …i><a href="#serverhttp2sessionaltsvcalt-originorstream"><code>serverhttp2session.altsvc(alt, origi…
169 <li><a href="#specifying-alternative-services">Specifying alternative services</a></li>
170 <li><a href="#serverhttp2sessionoriginorigins"><code>serverhttp2session.origin(...origins)</code></…
173 <li><a href="#class-clienthttp2session">Class: <code>ClientHttp2Session</code></a>
175 <li><a href="#event-altsvc">Event: <code>'altsvc'</code></a></li>
176 <li><a href="#event-origin">Event: <code>'origin'</code></a></li>
177 …<a href="#clienthttp2sessionrequestheaders-options"><code>clienthttp2session.request(headers[, opt…
180 <li><a href="#class-http2stream">Class: <code>Http2Stream</code></a>
182 <li><a href="#http2stream-lifecycle"><code>Http2Stream</code> Lifecycle</a>
188 <li><a href="#event-aborted">Event: <code>'aborted'</code></a></li>
189 <li><a href="#event-close_1">Event: <code>'close'</code></a></li>
190 <li><a href="#event-error_1">Event: <code>'error'</code></a></li>
191 <li><a href="#event-frameerror_1">Event: <code>'frameError'</code></a></li>
192 <li><a href="#event-ready">Event: <code>'ready'</code></a></li>
193 <li><a href="#event-timeout_1">Event: <code>'timeout'</code></a></li>
194 <li><a href="#event-trailers">Event: <code>'trailers'</code></a></li>
195 <li><a href="#event-wanttrailers">Event: <code>'wantTrailers'</code></a></li>
196 <li><a href="#http2streamaborted"><code>http2stream.aborted</code></a></li>
197 <li><a href="#http2streambuffersize"><code>http2stream.bufferSize</code></a></li>
198 <li><a href="#http2streamclosecode-callback"><code>http2stream.close(code[, callback])</code></a></…
199 <li><a href="#http2streamclosed"><code>http2stream.closed</code></a></li>
200 <li><a href="#http2streamdestroyed"><code>http2stream.destroyed</code></a></li>
201 <li><a href="#http2streamendafterheaders"><code>http2stream.endAfterHeaders</code></a></li>
202 <li><a href="#http2streamid"><code>http2stream.id</code></a></li>
203 <li><a href="#http2streampending"><code>http2stream.pending</code></a></li>
204 <li><a href="#http2streampriorityoptions"><code>http2stream.priority(options)</code></a></li>
205 <li><a href="#http2streamrstcode"><code>http2stream.rstCode</code></a></li>
206 <li><a href="#http2streamsentheaders"><code>http2stream.sentHeaders</code></a></li>
207 <li><a href="#http2streamsentinfoheaders"><code>http2stream.sentInfoHeaders</code></a></li>
208 <li><a href="#http2streamsenttrailers"><code>http2stream.sentTrailers</code></a></li>
209 <li><a href="#http2streamsession"><code>http2stream.session</code></a></li>
210 <li><a href="#http2streamsettimeoutmsecs-callback"><code>http2stream.setTimeout(msecs, callback)</c…
211 <li><a href="#http2streamstate"><code>http2stream.state</code></a></li>
212 <li><a href="#http2streamsendtrailersheaders"><code>http2stream.sendTrailers(headers)</code></a></l…
215 <li><a href="#class-clienthttp2stream">Class: <code>ClientHttp2Stream</code></a>
217 <li><a href="#event-continue">Event: <code>'continue'</code></a></li>
218 <li><a href="#event-headers">Event: <code>'headers'</code></a></li>
219 <li><a href="#event-push">Event: <code>'push'</code></a></li>
220 <li><a href="#event-response">Event: <code>'response'</code></a></li>
223 <li><a href="#class-serverhttp2stream">Class: <code>ServerHttp2Stream</code></a>
225 <li><a href="#http2streamadditionalheadersheaders"><code>http2stream.additionalHeaders(headers)</co…
226 <li><a href="#http2streamheaderssent"><code>http2stream.headersSent</code></a></li>
227 <li><a href="#http2streampushallowed"><code>http2stream.pushAllowed</code></a></li>
228 …href="#http2streampushstreamheaders-options-callback"><code>http2stream.pushStream(headers[, optio…
229 <li><a href="#http2streamrespondheaders-options"><code>http2stream.respond([headers[, options]])</c…
230 …<a href="#http2streamrespondwithfdfd-headers-options"><code>http2stream.respondWithFD(fd[, headers…
231 …f="#http2streamrespondwithfilepath-headers-options"><code>http2stream.respondWithFile(path[, heade…
234 <li><a href="#class-http2server">Class: <code>Http2Server</code></a>
236 <li><a href="#event-checkcontinue">Event: <code>'checkContinue'</code></a></li>
237 <li><a href="#event-connection">Event: <code>'connection'</code></a></li>
238 <li><a href="#event-request">Event: <code>'request'</code></a></li>
239 <li><a href="#event-session">Event: <code>'session'</code></a></li>
240 <li><a href="#event-sessionerror">Event: <code>'sessionError'</code></a></li>
241 <li><a href="#event-stream_1">Event: <code>'stream'</code></a></li>
242 <li><a href="#event-timeout_2">Event: <code>'timeout'</code></a></li>
243 <li><a href="#serverclosecallback"><code>server.close([callback])</code></a></li>
244 <li><a href="#serversettimeoutmsecs-callback"><code>server.setTimeout([msecs][, callback])</code></…
245 <li><a href="#servertimeout"><code>server.timeout</code></a></li>
246 <li><a href="#serverupdatesettingssettings"><code>server.updateSettings([settings])</code></a></li>
249 <li><a href="#class-http2secureserver">Class: <code>Http2SecureServer</code></a>
251 <li><a href="#event-checkcontinue_1">Event: <code>'checkContinue'</code></a></li>
252 <li><a href="#event-connection_1">Event: <code>'connection'</code></a></li>
253 <li><a href="#event-request_1">Event: <code>'request'</code></a></li>
254 <li><a href="#event-session_1">Event: <code>'session'</code></a></li>
255 <li><a href="#event-sessionerror_1">Event: <code>'sessionError'</code></a></li>
256 <li><a href="#event-stream_2">Event: <code>'stream'</code></a></li>
257 <li><a href="#event-timeout_3">Event: <code>'timeout'</code></a></li>
258 <li><a href="#event-unknownprotocol">Event: <code>'unknownProtocol'</code></a></li>
259 <li><a href="#serverclosecallback_1"><code>server.close([callback])</code></a></li>
260 <li><a href="#serversettimeoutmsecs-callback_1"><code>server.setTimeout([msecs][, callback])</code>…
261 <li><a href="#servertimeout_1"><code>server.timeout</code></a></li>
262 <li><a href="#serverupdatesettingssettings_1"><code>server.updateSettings([settings])</code></a></l…
265 …i><a href="#http2createserveroptions-onrequesthandler"><code>http2.createServer([options][, onRequ…
266 …f="#http2createsecureserveroptions-onrequesthandler"><code>http2.createSecureServer(options[, onRe…
267 <li><a href="#http2connectauthority-options-listener"><code>http2.connect(authority[, options][, li…
268 <li><a href="#http2constants"><code>http2.constants</code></a>
270 <li><a href="#error-codes-for-rst_stream-and-goaway">Error codes for <code>RST_STREAM</code> and <c…
273 <li><a href="#http2getdefaultsettings"><code>http2.getDefaultSettings()</code></a></li>
274 <li><a href="#http2getpackedsettingssettings"><code>http2.getPackedSettings([settings])</code></a><…
275 <li><a href="#http2getunpackedsettingsbuf"><code>http2.getUnpackedSettings(buf)</code></a></li>
276 <li><a href="#http2sensitiveheaders"><code>http2.sensitiveHeaders</code></a></li>
277 <li><a href="#headers-object">Headers object</a>
279 <li><a href="#sensitive-headers">Sensitive headers</a></li>
282 <li><a href="#settings-object">Settings object</a></li>
283 <li><a href="#error-handling">Error handling</a></li>
284 <li><a href="#invalid-character-handling-in-header-names-and-values">Invalid character handling in …
285 <li><a href="#push-streams-on-the-client">Push streams on the client</a></li>
286 <li><a href="#supporting-the-connect-method">Supporting the <code>CONNECT</code> method</a></li>
287 <li><a href="#the-extended-connect-protocol">The extended <code>CONNECT</code> protocol</a></li>
290 <li><a href="#compatibility-api">Compatibility API</a>
292 <li><a href="#alpn-negotiation">ALPN negotiation</a></li>
293 <li><a href="#class-http2http2serverrequest">Class: <code>http2.Http2ServerRequest</code></a>
295 <li><a href="#event-aborted_1">Event: <code>'aborted'</code></a></li>
296 <li><a href="#event-close_2">Event: <code>'close'</code></a></li>
297 <li><a href="#requestaborted"><code>request.aborted</code></a></li>
298 <li><a href="#requestauthority"><code>request.authority</code></a></li>
299 <li><a href="#requestcomplete"><code>request.complete</code></a></li>
300 <li><span class="stability_0"><a href="#requestconnection"><code>request.connection</code></a></spa…
301 <li><a href="#requestdestroyerror"><code>request.destroy([error])</code></a></li>
302 <li><a href="#requestheaders"><code>request.headers</code></a></li>
303 <li><a href="#requesthttpversion"><code>request.httpVersion</code></a></li>
304 <li><a href="#requestmethod"><code>request.method</code></a></li>
305 <li><a href="#requestrawheaders"><code>request.rawHeaders</code></a></li>
306 <li><a href="#requestrawtrailers"><code>request.rawTrailers</code></a></li>
307 <li><a href="#requestscheme"><code>request.scheme</code></a></li>
308 <li><a href="#requestsettimeoutmsecs-callback"><code>request.setTimeout(msecs, callback)</code></a>…
309 <li><a href="#requestsocket"><code>request.socket</code></a></li>
310 <li><a href="#requeststream"><code>request.stream</code></a></li>
311 <li><a href="#requesttrailers"><code>request.trailers</code></a></li>
312 <li><a href="#requesturl"><code>request.url</code></a></li>
315 <li><a href="#class-http2http2serverresponse">Class: <code>http2.Http2ServerResponse</code></a>
317 <li><a href="#event-close_3">Event: <code>'close'</code></a></li>
318 <li><a href="#event-finish">Event: <code>'finish'</code></a></li>
319 <li><a href="#responseaddtrailersheaders"><code>response.addTrailers(headers)</code></a></li>
320 <li><span class="stability_0"><a href="#responseconnection"><code>response.connection</code></a></s…
321 …a href="#responsecreatepushresponseheaders-callback"><code>response.createPushResponse(headers, ca…
322 <li><a href="#responseenddata-encoding-callback"><code>response.end([data[, encoding]][, callback])…
323 <li><span class="stability_0"><a href="#responsefinished"><code>response.finished</code></a></span>…
324 <li><a href="#responsegetheadername"><code>response.getHeader(name)</code></a></li>
325 <li><a href="#responsegetheadernames"><code>response.getHeaderNames()</code></a></li>
326 <li><a href="#responsegetheaders"><code>response.getHeaders()</code></a></li>
327 <li><a href="#responsehasheadername"><code>response.hasHeader(name)</code></a></li>
328 <li><a href="#responseheaderssent"><code>response.headersSent</code></a></li>
329 <li><a href="#responseremoveheadername"><code>response.removeHeader(name)</code></a></li>
330 <li><a href="#responsereq"><code>response.req</code></a></li>
331 <li><a href="#responsesenddate"><code>response.sendDate</code></a></li>
332 <li><a href="#responsesetheadername-value"><code>response.setHeader(name, value)</code></a></li>
333 <li><a href="#responsesettimeoutmsecs-callback"><code>response.setTimeout(msecs[, callback])</code>…
334 <li><a href="#responsesocket"><code>response.socket</code></a></li>
335 <li><a href="#responsestatuscode"><code>response.statusCode</code></a></li>
336 <li><a href="#responsestatusmessage"><code>response.statusMessage</code></a></li>
337 <li><a href="#responsestream"><code>response.stream</code></a></li>
338 <li><a href="#responsewritableended"><code>response.writableEnded</code></a></li>
339 <li><a href="#responsewritechunk-encoding-callback"><code>response.write(chunk[, encoding][, callba…
340 <li><a href="#responsewritecontinue"><code>response.writeContinue()</code></a></li>
341 <li><a href="#responsewriteearlyhintshints"><code>response.writeEarlyHints(hints)</code></a></li>
342 …"#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead(statusCode[, statusM…
347 <li><a href="#collecting-http2-performance-metrics">Collecting HTTP/2 performance metrics</a></li>
348 <li><a href="#note-on-authority-and-host">Note on <code>:authority</code> and <code>host</code></a>…
355 <li class="picker-header">
357 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
362 <li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
363 <li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
372 <li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
373 <li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
374 <li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
375 <li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
376 <li><a href="addons.html" class="nav-addons">C++ addons</a></li>
377 <li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
378 <li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
379 <li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
380 <li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
381 <li><a href="cli.html" class="nav-cli">Command-line options</a></li>
382 <li><a href="console.html" class="nav-console">Console</a></li>
383 <li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
384 <li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
385 <li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
386 <li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
387 <li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
388 <li><a href="dns.html" class="nav-dns">DNS</a></li>
389 <li><a href="domain.html" class="nav-domain">Domain</a></li>
390 <li><a href="errors.html" class="nav-errors">Errors</a></li>
391 <li><a href="events.html" class="nav-events">Events</a></li>
392 <li><a href="fs.html" class="nav-fs">File system</a></li>
393 <li><a href="globals.html" class="nav-globals">Globals</a></li>
394 <li><a href="http.html" class="nav-http">HTTP</a></li>
395 <li><a href="http2.html" class="nav-http2 active">HTTP/2</a></li>
396 <li><a href="https.html" class="nav-https">HTTPS</a></li>
397 <li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
398 <li><a href="intl.html" class="nav-intl">Internationalization</a></li>
399 <li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
400 <li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
401 <li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
402 <li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
403 <li><a href="net.html" class="nav-net">Net</a></li>
404 <li><a href="os.html" class="nav-os">OS</a></li>
405 <li><a href="path.html" class="nav-path">Path</a></li>
406 <li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
407 <li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
408 <li><a href="process.html" class="nav-process">Process</a></li>
409 <li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
410 <li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
411 <li><a href="readline.html" class="nav-readline">Readline</a></li>
412 <li><a href="repl.html" class="nav-repl">REPL</a></li>
413 <li><a href="report.html" class="nav-report">Report</a></li>
414 <li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single…
415 <li><a href="stream.html" class="nav-stream">Stream</a></li>
416 <li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
417 <li><a href="test.html" class="nav-test">Test runner</a></li>
418 <li><a href="timers.html" class="nav-timers">Timers</a></li>
419 <li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
420 <li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
421 <li><a href="tty.html" class="nav-tty">TTY</a></li>
422 <li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
423 <li><a href="url.html" class="nav-url">URL</a></li>
424 <li><a href="util.html" class="nav-util">Utilities</a></li>
425 <li><a href="v8.html" class="nav-v8">V8</a></li>
426 <li><a href="vm.html" class="nav-vm">VM</a></li>
427 <li><a href="wasi.html" class="nav-wasi">WASI</a></li>
428 <li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
429 <li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
430 <li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
431 <li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
435 <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code reposito…
440 <li class="picker-header">
442 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
445 …<div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/http2.…
446 <li><a href="https://nodejs.org/docs/latest-v20.x/api/http2.html">20.x <b>LTS</b></a></li>
447 <li><a href="https://nodejs.org/docs/latest-v19.x/api/http2.html">19.x</a></li>
448 <li><a href="https://nodejs.org/docs/latest-v18.x/api/http2.html">18.x <b>LTS</b></a></li>
449 <li><a href="https://nodejs.org/docs/latest-v17.x/api/http2.html">17.x</a></li>
450 <li><a href="https://nodejs.org/docs/latest-v16.x/api/http2.html">16.x</a></li>
451 <li><a href="https://nodejs.org/docs/latest-v15.x/api/http2.html">15.x</a></li>
452 <li><a href="https://nodejs.org/docs/latest-v14.x/api/http2.html">14.x</a></li>
453 <li><a href="https://nodejs.org/docs/latest-v13.x/api/http2.html">13.x</a></li>
454 <li><a href="https://nodejs.org/docs/latest-v12.x/api/http2.html">12.x</a></li>
455 <li><a href="https://nodejs.org/docs/latest-v11.x/api/http2.html">11.x</a></li>
456 <li><a href="https://nodejs.org/docs/latest-v10.x/api/http2.html">10.x</a></li>
457 <li><a href="https://nodejs.org/docs/latest-v9.x/api/http2.html">9.x</a></li>
458 <li><a href="https://nodejs.org/docs/latest-v8.x/api/http2.html">8.x</a></li></ol></div>
461 <li class="picker-header">
463 … <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
487 <li><a href="#determining-if-crypto-support-is-unavailable">Determining if crypto support is unavai…
488 <li><a href="#core-api">Core API</a>
490 <li><a href="#server-side-example">Server-side example</a></li>
491 <li><a href="#client-side-example">Client-side example</a></li>
492 <li><a href="#class-http2session">Class: <code>Http2Session</code></a>
494 <li><a href="#http2session-and-sockets"><code>Http2Session</code> and sockets</a></li>
495 <li><a href="#event-close">Event: <code>'close'</code></a></li>
496 <li><a href="#event-connect">Event: <code>'connect'</code></a></li>
497 <li><a href="#event-error">Event: <code>'error'</code></a></li>
498 <li><a href="#event-frameerror">Event: <code>'frameError'</code></a></li>
499 <li><a href="#event-goaway">Event: <code>'goaway'</code></a></li>
500 <li><a href="#event-localsettings">Event: <code>'localSettings'</code></a></li>
501 <li><a href="#event-ping">Event: <code>'ping'</code></a></li>
502 <li><a href="#event-remotesettings">Event: <code>'remoteSettings'</code></a></li>
503 <li><a href="#event-stream">Event: <code>'stream'</code></a></li>
504 <li><a href="#event-timeout">Event: <code>'timeout'</code></a></li>
505 <li><a href="#http2sessionalpnprotocol"><code>http2session.alpnProtocol</code></a></li>
506 <li><a href="#http2sessionclosecallback"><code>http2session.close([callback])</code></a></li>
507 <li><a href="#http2sessionclosed"><code>http2session.closed</code></a></li>
508 <li><a href="#http2sessionconnecting"><code>http2session.connecting</code></a></li>
509 <li><a href="#http2sessiondestroyerror-code"><code>http2session.destroy([error][, code])</code></a>…
510 <li><a href="#http2sessiondestroyed"><code>http2session.destroyed</code></a></li>
511 <li><a href="#http2sessionencrypted"><code>http2session.encrypted</code></a></li>
512 …href="#http2sessiongoawaycode-laststreamid-opaquedata"><code>http2session.goaway([code[, lastStrea…
513 <li><a href="#http2sessionlocalsettings"><code>http2session.localSettings</code></a></li>
514 <li><a href="#http2sessionoriginset"><code>http2session.originSet</code></a></li>
515 <li><a href="#http2sessionpendingsettingsack"><code>http2session.pendingSettingsAck</code></a></li>
516 <li><a href="#http2sessionpingpayload-callback"><code>http2session.ping([payload, ]callback)</code>…
517 <li><a href="#http2sessionref"><code>http2session.ref()</code></a></li>
518 <li><a href="#http2sessionremotesettings"><code>http2session.remoteSettings</code></a></li>
519 …ref="#http2sessionsetlocalwindowsizewindowsize"><code>http2session.setLocalWindowSize(windowSize)<…
520 <li><a href="#http2sessionsettimeoutmsecs-callback"><code>http2session.setTimeout(msecs, callback)<…
521 <li><a href="#http2sessionsocket"><code>http2session.socket</code></a></li>
522 <li><a href="#http2sessionstate"><code>http2session.state</code></a></li>
523 <li><a href="#http2sessionsettingssettings-callback"><code>http2session.settings([settings][, callb…
524 <li><a href="#http2sessiontype"><code>http2session.type</code></a></li>
525 <li><a href="#http2sessionunref"><code>http2session.unref()</code></a></li>
528 <li><a href="#class-serverhttp2session">Class: <code>ServerHttp2Session</code></a>
530 …i><a href="#serverhttp2sessionaltsvcalt-originorstream"><code>serverhttp2session.altsvc(alt, origi…
531 <li><a href="#specifying-alternative-services">Specifying alternative services</a></li>
532 <li><a href="#serverhttp2sessionoriginorigins"><code>serverhttp2session.origin(...origins)</code></…
535 <li><a href="#class-clienthttp2session">Class: <code>ClientHttp2Session</code></a>
537 <li><a href="#event-altsvc">Event: <code>'altsvc'</code></a></li>
538 <li><a href="#event-origin">Event: <code>'origin'</code></a></li>
539 …<a href="#clienthttp2sessionrequestheaders-options"><code>clienthttp2session.request(headers[, opt…
542 <li><a href="#class-http2stream">Class: <code>Http2Stream</code></a>
544 <li><a href="#http2stream-lifecycle"><code>Http2Stream</code> Lifecycle</a>
550 <li><a href="#event-aborted">Event: <code>'aborted'</code></a></li>
551 <li><a href="#event-close_1">Event: <code>'close'</code></a></li>
552 <li><a href="#event-error_1">Event: <code>'error'</code></a></li>
553 <li><a href="#event-frameerror_1">Event: <code>'frameError'</code></a></li>
554 <li><a href="#event-ready">Event: <code>'ready'</code></a></li>
555 <li><a href="#event-timeout_1">Event: <code>'timeout'</code></a></li>
556 <li><a href="#event-trailers">Event: <code>'trailers'</code></a></li>
557 <li><a href="#event-wanttrailers">Event: <code>'wantTrailers'</code></a></li>
558 <li><a href="#http2streamaborted"><code>http2stream.aborted</code></a></li>
559 <li><a href="#http2streambuffersize"><code>http2stream.bufferSize</code></a></li>
560 <li><a href="#http2streamclosecode-callback"><code>http2stream.close(code[, callback])</code></a></…
561 <li><a href="#http2streamclosed"><code>http2stream.closed</code></a></li>
562 <li><a href="#http2streamdestroyed"><code>http2stream.destroyed</code></a></li>
563 <li><a href="#http2streamendafterheaders"><code>http2stream.endAfterHeaders</code></a></li>
564 <li><a href="#http2streamid"><code>http2stream.id</code></a></li>
565 <li><a href="#http2streampending"><code>http2stream.pending</code></a></li>
566 <li><a href="#http2streampriorityoptions"><code>http2stream.priority(options)</code></a></li>
567 <li><a href="#http2streamrstcode"><code>http2stream.rstCode</code></a></li>
568 <li><a href="#http2streamsentheaders"><code>http2stream.sentHeaders</code></a></li>
569 <li><a href="#http2streamsentinfoheaders"><code>http2stream.sentInfoHeaders</code></a></li>
570 <li><a href="#http2streamsenttrailers"><code>http2stream.sentTrailers</code></a></li>
571 <li><a href="#http2streamsession"><code>http2stream.session</code></a></li>
572 <li><a href="#http2streamsettimeoutmsecs-callback"><code>http2stream.setTimeout(msecs, callback)</c…
573 <li><a href="#http2streamstate"><code>http2stream.state</code></a></li>
574 <li><a href="#http2streamsendtrailersheaders"><code>http2stream.sendTrailers(headers)</code></a></l…
577 <li><a href="#class-clienthttp2stream">Class: <code>ClientHttp2Stream</code></a>
579 <li><a href="#event-continue">Event: <code>'continue'</code></a></li>
580 <li><a href="#event-headers">Event: <code>'headers'</code></a></li>
581 <li><a href="#event-push">Event: <code>'push'</code></a></li>
582 <li><a href="#event-response">Event: <code>'response'</code></a></li>
585 <li><a href="#class-serverhttp2stream">Class: <code>ServerHttp2Stream</code></a>
587 <li><a href="#http2streamadditionalheadersheaders"><code>http2stream.additionalHeaders(headers)</co…
588 <li><a href="#http2streamheaderssent"><code>http2stream.headersSent</code></a></li>
589 <li><a href="#http2streampushallowed"><code>http2stream.pushAllowed</code></a></li>
590 …href="#http2streampushstreamheaders-options-callback"><code>http2stream.pushStream(headers[, optio…
591 <li><a href="#http2streamrespondheaders-options"><code>http2stream.respond([headers[, options]])</c…
592 …<a href="#http2streamrespondwithfdfd-headers-options"><code>http2stream.respondWithFD(fd[, headers…
593 …f="#http2streamrespondwithfilepath-headers-options"><code>http2stream.respondWithFile(path[, heade…
596 <li><a href="#class-http2server">Class: <code>Http2Server</code></a>
598 <li><a href="#event-checkcontinue">Event: <code>'checkContinue'</code></a></li>
599 <li><a href="#event-connection">Event: <code>'connection'</code></a></li>
600 <li><a href="#event-request">Event: <code>'request'</code></a></li>
601 <li><a href="#event-session">Event: <code>'session'</code></a></li>
602 <li><a href="#event-sessionerror">Event: <code>'sessionError'</code></a></li>
603 <li><a href="#event-stream_1">Event: <code>'stream'</code></a></li>
604 <li><a href="#event-timeout_2">Event: <code>'timeout'</code></a></li>
605 <li><a href="#serverclosecallback"><code>server.close([callback])</code></a></li>
606 <li><a href="#serversettimeoutmsecs-callback"><code>server.setTimeout([msecs][, callback])</code></…
607 <li><a href="#servertimeout"><code>server.timeout</code></a></li>
608 <li><a href="#serverupdatesettingssettings"><code>server.updateSettings([settings])</code></a></li>
611 <li><a href="#class-http2secureserver">Class: <code>Http2SecureServer</code></a>
613 <li><a href="#event-checkcontinue_1">Event: <code>'checkContinue'</code></a></li>
614 <li><a href="#event-connection_1">Event: <code>'connection'</code></a></li>
615 <li><a href="#event-request_1">Event: <code>'request'</code></a></li>
616 <li><a href="#event-session_1">Event: <code>'session'</code></a></li>
617 <li><a href="#event-sessionerror_1">Event: <code>'sessionError'</code></a></li>
618 <li><a href="#event-stream_2">Event: <code>'stream'</code></a></li>
619 <li><a href="#event-timeout_3">Event: <code>'timeout'</code></a></li>
620 <li><a href="#event-unknownprotocol">Event: <code>'unknownProtocol'</code></a></li>
621 <li><a href="#serverclosecallback_1"><code>server.close([callback])</code></a></li>
622 <li><a href="#serversettimeoutmsecs-callback_1"><code>server.setTimeout([msecs][, callback])</code>…
623 <li><a href="#servertimeout_1"><code>server.timeout</code></a></li>
624 <li><a href="#serverupdatesettingssettings_1"><code>server.updateSettings([settings])</code></a></l…
627 …i><a href="#http2createserveroptions-onrequesthandler"><code>http2.createServer([options][, onRequ…
628 …f="#http2createsecureserveroptions-onrequesthandler"><code>http2.createSecureServer(options[, onRe…
629 <li><a href="#http2connectauthority-options-listener"><code>http2.connect(authority[, options][, li…
630 <li><a href="#http2constants"><code>http2.constants</code></a>
632 <li><a href="#error-codes-for-rst_stream-and-goaway">Error codes for <code>RST_STREAM</code> and <c…
635 <li><a href="#http2getdefaultsettings"><code>http2.getDefaultSettings()</code></a></li>
636 <li><a href="#http2getpackedsettingssettings"><code>http2.getPackedSettings([settings])</code></a><…
637 <li><a href="#http2getunpackedsettingsbuf"><code>http2.getUnpackedSettings(buf)</code></a></li>
638 <li><a href="#http2sensitiveheaders"><code>http2.sensitiveHeaders</code></a></li>
639 <li><a href="#headers-object">Headers object</a>
641 <li><a href="#sensitive-headers">Sensitive headers</a></li>
644 <li><a href="#settings-object">Settings object</a></li>
645 <li><a href="#error-handling">Error handling</a></li>
646 <li><a href="#invalid-character-handling-in-header-names-and-values">Invalid character handling in …
647 <li><a href="#push-streams-on-the-client">Push streams on the client</a></li>
648 <li><a href="#supporting-the-connect-method">Supporting the <code>CONNECT</code> method</a></li>
649 <li><a href="#the-extended-connect-protocol">The extended <code>CONNECT</code> protocol</a></li>
652 <li><a href="#compatibility-api">Compatibility API</a>
654 <li><a href="#alpn-negotiation">ALPN negotiation</a></li>
655 <li><a href="#class-http2http2serverrequest">Class: <code>http2.Http2ServerRequest</code></a>
657 <li><a href="#event-aborted_1">Event: <code>'aborted'</code></a></li>
658 <li><a href="#event-close_2">Event: <code>'close'</code></a></li>
659 <li><a href="#requestaborted"><code>request.aborted</code></a></li>
660 <li><a href="#requestauthority"><code>request.authority</code></a></li>
661 <li><a href="#requestcomplete"><code>request.complete</code></a></li>
662 <li><span class="stability_0"><a href="#requestconnection"><code>request.connection</code></a></spa…
663 <li><a href="#requestdestroyerror"><code>request.destroy([error])</code></a></li>
664 <li><a href="#requestheaders"><code>request.headers</code></a></li>
665 <li><a href="#requesthttpversion"><code>request.httpVersion</code></a></li>
666 <li><a href="#requestmethod"><code>request.method</code></a></li>
667 <li><a href="#requestrawheaders"><code>request.rawHeaders</code></a></li>
668 <li><a href="#requestrawtrailers"><code>request.rawTrailers</code></a></li>
669 <li><a href="#requestscheme"><code>request.scheme</code></a></li>
670 <li><a href="#requestsettimeoutmsecs-callback"><code>request.setTimeout(msecs, callback)</code></a>…
671 <li><a href="#requestsocket"><code>request.socket</code></a></li>
672 <li><a href="#requeststream"><code>request.stream</code></a></li>
673 <li><a href="#requesttrailers"><code>request.trailers</code></a></li>
674 <li><a href="#requesturl"><code>request.url</code></a></li>
677 <li><a href="#class-http2http2serverresponse">Class: <code>http2.Http2ServerResponse</code></a>
679 <li><a href="#event-close_3">Event: <code>'close'</code></a></li>
680 <li><a href="#event-finish">Event: <code>'finish'</code></a></li>
681 <li><a href="#responseaddtrailersheaders"><code>response.addTrailers(headers)</code></a></li>
682 <li><span class="stability_0"><a href="#responseconnection"><code>response.connection</code></a></s…
683 …a href="#responsecreatepushresponseheaders-callback"><code>response.createPushResponse(headers, ca…
684 <li><a href="#responseenddata-encoding-callback"><code>response.end([data[, encoding]][, callback])…
685 <li><span class="stability_0"><a href="#responsefinished"><code>response.finished</code></a></span>…
686 <li><a href="#responsegetheadername"><code>response.getHeader(name)</code></a></li>
687 <li><a href="#responsegetheadernames"><code>response.getHeaderNames()</code></a></li>
688 <li><a href="#responsegetheaders"><code>response.getHeaders()</code></a></li>
689 <li><a href="#responsehasheadername"><code>response.hasHeader(name)</code></a></li>
690 <li><a href="#responseheaderssent"><code>response.headersSent</code></a></li>
691 <li><a href="#responseremoveheadername"><code>response.removeHeader(name)</code></a></li>
692 <li><a href="#responsereq"><code>response.req</code></a></li>
693 <li><a href="#responsesenddate"><code>response.sendDate</code></a></li>
694 <li><a href="#responsesetheadername-value"><code>response.setHeader(name, value)</code></a></li>
695 <li><a href="#responsesettimeoutmsecs-callback"><code>response.setTimeout(msecs[, callback])</code>…
696 <li><a href="#responsesocket"><code>response.socket</code></a></li>
697 <li><a href="#responsestatuscode"><code>response.statusCode</code></a></li>
698 <li><a href="#responsestatusmessage"><code>response.statusMessage</code></a></li>
699 <li><a href="#responsestream"><code>response.stream</code></a></li>
700 <li><a href="#responsewritableended"><code>response.writableEnded</code></a></li>
701 <li><a href="#responsewritechunk-encoding-callback"><code>response.write(chunk[, encoding][, callba…
702 <li><a href="#responsewritecontinue"><code>response.writeContinue()</code></a></li>
703 <li><a href="#responsewriteearlyhintshints"><code>response.writeEarlyHints(hints)</code></a></li>
704 …"#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead(statusCode[, statusM…
709 <li><a href="#collecting-http2-performance-metrics">Collecting HTTP/2 performance metrics</a></li>
710 <li><a href="#note-on-authority-and-host">Note on <code>:authority</code> and <code>host</code></a>…
716 …<h2>HTTP/2<span><a class="mark" href="#http2" id="http2">#</a></span><a aria-hidden="true" class="…
722 <td><p>Requests with the <code>host</code> header (with or without <code>:authority</code>) can now…
733 …tability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</…
734 <p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/http2.js…
735 <p>The <code>node:http2</code> module provides an implementation of the <a href="https://tools.ietf…
737 …code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-built_i…
738 …mark" href="#determining-if-crypto-support-is-unavailable" id="determining-if-crypto-support-is-un…
740 <code>node:crypto</code> module. In such cases, attempting to <code>import</code> from <code>node:h…
741 calling <code>require('node:http2')</code> will result in an error being thrown.</p>
743 <pre><code class="language-js cjs"><span class="hljs-keyword">let</span> http2;
744 <span class="hljs-keyword">try</span> {
745 http2 = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:http2'</span>);
746 } <span class="hljs-keyword">catch</span> (err) {
747 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</spa…
748 }</code> <button class="copy-button">copy</button></pre>
749 <p>When using the lexical ESM <code>import</code> keyword, the error can only be
750 caught if a handler for <code>process.on('uncaughtException')</code> is registered
753 <p>When using ESM, if there is a chance that the code may be run on a build
755 …zilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import"><code>import()</code></a> function…
756 <pre><code class="language-js mjs"><span class="hljs-keyword">let</span> http2;
757 <span class="hljs-keyword">try</span> {
758 …http2 = <span class="hljs-keyword">await</span> <span class="hljs-keyword">import</span>(<span cla…
759 } <span class="hljs-keyword">catch</span> (err) {
760 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</spa…
761 }</code> <button class="copy-button">copy</button></pre>
762 …n><section><h3>Core API<span><a class="mark" href="#core-api" id="core-api">#</a></span><a aria-hi…
763 <p>The Core API provides a low-level interface designed specifically around
766 the <a href="#compatibility-api">Compatibility API</a> is.</p>
767 <p>The <code>http2</code> Core API is much more symmetric between client and server than the
768 <code>http</code> API. For instance, most events, like <code>'error'</code>, <code>'connect'</code>…
769 <code>'stream'</code>, can be emitted either by client-side code or server-side code.</p>
770 <h4>Server-side example<span><a class="mark" href="#server-side-example" id="server-side-example">#…
773 <a href="https://http2.github.io/faq/#does-http2-require-encryption">unencrypted HTTP/2</a>, the us…
774 <a href="#http2createsecureserveroptions-onrequesthandler"><code>http2.createSecureServer()</code><…
776 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
777 <span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class…
779 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSec…
780 …<span class="hljs-attr">key</span>: fs.<span class="hljs-title function_">readFileSync</span>(<spa…
781 …<span class="hljs-attr">cert</span>: fs.<span class="hljs-title function_">readFileSync</span>(<sp…
783 …-title function_">on</span>(<span class="hljs-string">'error'</span>, <span class="hljs-function">…
785 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
786 <span class="hljs-comment">// stream is a Duplex</span>
787 stream.<span class="hljs-title function_">respond</span>({
788 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/html; charset=utf…
789 <span class="hljs-string">':status'</span>: <span class="hljs-number">200</span>,
791 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'<h1>Hello Wor…
794 server.<span class="hljs-title function_">listen</span>(<span class="hljs-number">8443</span>);</co…
796 <pre><code class="language-bash">openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj <span clas…
797 …-keyout localhost-privkey.pem -out localhost-cert.pem</code> <button class="copy-button">copy</but…
798 <h4>Client-side example<span><a class="mark" href="#client-side-example" id="client-side-example">#…
800 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
801 <span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class…
802 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
803 …<span class="hljs-attr">ca</span>: fs.<span class="hljs-title function_">readFileSync</span>(<span…
805 …-title function_">on</span>(<span class="hljs-string">'error'</span>, <span class="hljs-function">…
807 …js-keyword">const</span> req = client.<span class="hljs-title function_">request</span>({ <span cl…
809 …span class="hljs-title function_">on</span>(<span class="hljs-string">'response'</span>, <span cla…
810 …<span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> name <span class="h…
811 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hlj…
815 req.<span class="hljs-title function_">setEncoding</span>(<span class="hljs-string">'utf8'</span>);
816 <span class="hljs-keyword">let</span> data = <span class="hljs-string">''</span>;
817 ….<span class="hljs-title function_">on</span>(<span class="hljs-string">'data'</span>, <span class…
818 req.<span class="hljs-title function_">on</span>(<span class="hljs-string">'end'</span>, <span clas…
819 … class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<spa…
820 client.<span class="hljs-title function_">close</span>();
822 req.<span class="hljs-title function_">end</span>();</code> <button class="copy-button">copy</butto…
823 <h4>Class: <code>Http2Session</code><span><a class="mark" href="#class-http2session" id="class-http…
828 <li>Extends: <a href="events.html#class-eventemitter" class="type"><EventEmitter></a></li>
830 <p>Instances of the <code>http2.Http2Session</code> class represent an active communications
832 intended to be constructed directly by user code.</p>
833 <p>Each <code>Http2Session</code> instance will exhibit slightly different behaviors
835 <code>http2session.type</code> property can be used to determine the mode in which an
836 <code>Http2Session</code> is operating. On the server side, user code should rarely
837 have occasion to work with the <code>Http2Session</code> object directly, with most
838 actions typically taken through interactions with either the <code>Http2Server</code> or
839 <code>Http2Stream</code> objects.</p>
840 <p>User code will not create <code>Http2Session</code> instances directly. Server-side
841 <code>Http2Session</code> instances are created by the <code>Http2Server</code> instance when a
842 new HTTP/2 connection is received. Client-side <code>Http2Session</code> instances are
843 created using the <code>http2.connect()</code> method.</p>
844 <h5><code>Http2Session</code> and sockets<span><a class="mark" href="#http2session-and-sockets" id=…
845 <p>Every <code>Http2Session</code> instance is associated with exactly one <a href="net.html#class-…
846 <a href="tls.html#class-tlstlssocket"><code>tls.TLSSocket</code></a> when it is created. When eithe…
847 <code>Http2Session</code> are destroyed, both will be destroyed.</p>
849 by the HTTP/2 protocol, it is not recommended for user code to read data from
850 or write data to a <code>Socket</code> instance bound to a <code>Http2Session</code>. Doing so can
853 <p>Once a <code>Socket</code> has been bound to an <code>Http2Session</code>, user code should rely
854 solely on the API of the <code>Http2Session</code>.</p>
855 <h5>Event: <code>'close'</code><span><a class="mark" href="#event-close" id="event-close">#</a></sp…
859 <p>The <code>'close'</code> event is emitted once the <code>Http2Session</code> has been destroyed.…
861 <h5>Event: <code>'connect'</code><span><a class="mark" href="#event-connect" id="event-connect">#</…
866 <li><code>session</code> <a href="http2.html#class-http2session" class="type"><Http2Session></…
867 <li><code>socket</code> <a href="net.html#class-netsocket" class="type"><net.Socket></a></li>
869 <p>The <code>'connect'</code> event is emitted once the <code>Http2Session</code> has been successf…
871 <p>User code will typically not listen for this event directly.</p>
872 <h5>Event: <code>'error'</code><span><a class="mark" href="#event-error" id="event-error">#</a></sp…
877 <li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
879 <p>The <code>'error'</code> event is emitted when an error occurs during the processing of
880 an <code>Http2Session</code>.</p>
881 <h5>Event: <code>'frameError'</code><span><a class="mark" href="#event-frameerror" id="event-framee…
886 <li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
887 …code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
888 …code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Nu…
891 <p>The <code>'frameError'</code> event is emitted when an error occurs while attempting to
893 with a specific <code>Http2Stream</code>, an attempt to emit a <code>'frameError'</code> event on t…
894 <code>Http2Stream</code> is made.</p>
895 <p>If the <code>'frameError'</code> event is associated with a stream, the stream will be
896 closed and destroyed immediately following the <code>'frameError'</code> event. If the
897 event is not associated with a stream, the <code>Http2Session</code> will be shut down
898 immediately following the <code>'frameError'</code> event.</p>
899 <h5>Event: <code>'goaway'</code><span><a class="mark" href="#event-goaway" id="event-goaway">#</a><…
904 …code>errorCode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
905 <li><code>lastStreamID</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data…
906 processed (or <code>0</code> if no ID is specified).</li>
907 …code>opaqueData</code> <a href="buffer.html#class-buffer" class="type"><Buffer></a> If additi…
908 frame, a <code>Buffer</code> instance will be passed containing that data.</li>
910 <p>The <code>'goaway'</code> event is emitted when a <code>GOAWAY</code> frame is received.</p>
911 <p>The <code>Http2Session</code> instance will be shut down automatically when the <code>'goaway'</…
913 <h5>Event: <code>'localSettings'</code><span><a class="mark" href="#event-localsettings" id="event-…
918 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
920 <p>The <code>'localSettings'</code> event is emitted when an acknowledgment <code>SETTINGS</code> f…
922 <p>When using <code>http2session.settings()</code> to submit new settings, the modified
923 settings do not take effect until the <code>'localSettings'</code> event is emitted.</p>
924 …e><code class="language-js">session.<span class="hljs-title function_">settings</span>({ <span cla…
926 …an class="hljs-title function_">on</span>(<span class="hljs-string">'localSettings'</span>, <span …
927 <span class="hljs-comment">/* Use the new settings */</span>
928 });</code> <button class="copy-button">copy</button></pre>
929 <h5>Event: <code>'ping'</code><span><a class="mark" href="#event-ping" id="event-ping">#</a></span>…
934 <li><code>payload</code> <a href="buffer.html#class-buffer" class="type"><Buffer></a> The <cod…
936 <p>The <code>'ping'</code> event is emitted whenever a <code>PING</code> frame is received from the
938 <h5>Event: <code>'remoteSettings'</code><span><a class="mark" href="#event-remotesettings" id="even…
943 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
945 <p>The <code>'remoteSettings'</code> event is emitted when a new <code>SETTINGS</code> frame is rec…
947 …code class="language-js">session.<span class="hljs-title function_">on</span>(<span class="hljs-st…
948 <span class="hljs-comment">/* Use the new settings */</span>
949 });</code> <button class="copy-button">copy</button></pre>
950 <h5>Event: <code>'stream'</code><span><a class="mark" href="#event-stream" id="event-stream">#</a><…
955 <li><code>stream</code> <a href="http2.html#class-http2stream" class="type"><Http2Stream></a> …
956 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
957 <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
958 <li><code>rawHeaders</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere…
961 <p>The <code>'stream'</code> event is emitted when a new <code>Http2Stream</code> is created.</p>
962 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
963 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
964 …<span class="hljs-keyword">const</span> method = headers[<span class="hljs-string">':method'</span…
965 <span class="hljs-keyword">const</span> path = headers[<span class="hljs-string">':path'</span>];
966 <span class="hljs-comment">// ...</span>
967 stream.<span class="hljs-title function_">respond</span>({
968 <span class="hljs-string">':status'</span>: <span class="hljs-number">200</span>,
969 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/plain; charset=ut…
971 stream.<span class="hljs-title function_">write</span>(<span class="hljs-string">'hello '</span>);
972 stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'world'</span>);
973 });</code> <button class="copy-button">copy</button></pre>
974 <p>On the server side, user code will typically not listen for this event directly,
975 and would instead register a handler for the <code>'stream'</code> event emitted by the
976 <code>net.Server</code> or <code>tls.Server</code> instances returned by <code>http2.createServer()…
977 <code>http2.createSecureServer()</code>, respectively, as in the example below:</p>
978 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
980 <span class="hljs-comment">// Create an unencrypted HTTP/2 server</span>
981 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
983 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
984 stream.<span class="hljs-title function_">respond</span>({
985 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/html; charset=utf…
986 <span class="hljs-string">':status'</span>: <span class="hljs-number">200</span>,
988 …-title function_">on</span>(<span class="hljs-string">'error'</span>, <span class="hljs-function">…
989 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'<h1>Hello Wor…
992 server.<span class="hljs-title function_">listen</span>(<span class="hljs-number">8000</span>);</co…
996 <h5>Event: <code>'timeout'</code><span><a class="mark" href="#event-timeout" id="event-timeout">#</…
1000 <p>After the <code>http2session.setTimeout()</code> method is used to set the timeout period
1001 for this <code>Http2Session</code>, the <code>'timeout'</code> event is emitted if there is no
1002 activity on the <code>Http2Session</code> after the configured number of milliseconds.
1004 <pre><code class="language-js">session.<span class="hljs-built_in">setTimeout</span>(<span class="h…
1005 …-title function_">on</span>(<span class="hljs-string">'timeout'</span>, <span class="hljs-function…
1006 <h5><code>http2session.alpnProtocol</code><span><a class="mark" href="#http2sessionalpnprotocol" id…
1011 …zilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | …
1013 <p>Value will be <code>undefined</code> if the <code>Http2Session</code> is not yet connected to a
1014 socket, <code>h2c</code> if the <code>Http2Session</code> is not connected to a <code>TLSSocket</co…
1015 will return the value of the connected <code>TLSSocket</code>'s own <code>alpnProtocol</code>
1017 …><code>http2session.close([callback])</code><span><a class="mark" href="#http2sessionclosecallback…
1022 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1024 <p>Gracefully closes the <code>Http2Session</code>, allowing any existing streams to
1025 complete on their own and preventing new <code>Http2Stream</code> instances from being
1026 created. Once closed, <code>http2session.destroy()</code> <em>might</em> be called if there
1027 are no open <code>Http2Stream</code> instances.</p>
1028 <p>If specified, the <code>callback</code> function is registered as a handler for the
1029 <code>'close'</code> event.</p>
1030 <h5><code>http2session.closed</code><span><a class="mark" href="#http2sessionclosed" id="http2sessi…
1035 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1037 <p>Will be <code>true</code> if this <code>Http2Session</code> instance has been closed, otherwise
1038 <code>false</code>.</p>
1039 <h5><code>http2session.connecting</code><span><a class="mark" href="#http2sessionconnecting" id="ht…
1044 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1046 <p>Will be <code>true</code> if this <code>Http2Session</code> instance is still connecting, will b…
1047 to <code>false</code> before emitting <code>connect</code> event and/or calling the <code>http2.con…
1049 …code>http2session.destroy([error][, code])</code><span><a class="mark" href="#http2sessiondestroye…
1054 …code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Globa…
1056 …code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
1057 If unspecified, and <code>error</code> is not undefined, the default is <code>INTERNAL_ERROR</code>,
1058 otherwise defaults to <code>NO_ERROR</code>.</li>
1060 <p>Immediately terminates the <code>Http2Session</code> and the associated <code>net.Socket</code> …
1061 <code>tls.TLSSocket</code>.</p>
1062 <p>Once destroyed, the <code>Http2Session</code> will emit the <code>'close'</code> event. If <code…
1063 is not undefined, an <code>'error'</code> event will be emitted immediately before the
1064 <code>'close'</code> event.</p>
1065 <p>If there are any remaining open <code>Http2Streams</code> associated with the
1066 <code>Http2Session</code>, those will also be destroyed.</p>
1067 <h5><code>http2session.destroyed</code><span><a class="mark" href="#http2sessiondestroyed" id="http…
1072 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1074 <p>Will be <code>true</code> if this <code>Http2Session</code> instance has been destroyed and must…
1075 longer be used, otherwise <code>false</code>.</p>
1076 <h5><code>http2session.encrypted</code><span><a class="mark" href="#http2sessionencrypted" id="http…
1081 …illa.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> |…
1083 <p>Value is <code>undefined</code> if the <code>Http2Session</code> session socket has not yet been
1084 connected, <code>true</code> if the <code>Http2Session</code> is connected with a <code>TLSSocket</…
1085 and <code>false</code> if the <code>Http2Session</code> is connected to any other kind of socket
1087 …code>http2session.goaway([code[, lastStreamID[, opaqueData]]])</code><span><a class="mark" href="#…
1092 …code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
1093 …code>lastStreamID</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1094 …code>opaqueData</code> <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href…
1095 instance containing additional data to be carried within the <code>GOAWAY</code> frame.</li>
1097 <p>Transmits a <code>GOAWAY</code> frame to the connected peer <em>without</em> shutting down the
1098 <code>Http2Session</code>.</p>
1099 …h5><code>http2session.localSettings</code><span><a class="mark" href="#http2sessionlocalsettings" …
1104 <li><a href="http2.html#settings-object" class="type"><HTTP/2 Settings Object></a></li>
1106 <p>A prototype-less object describing the current local settings of this
1107 <code>Http2Session</code>. The local settings are local to <em>this</em> <code>Http2Session</code> …
1108 <h5><code>http2session.originSet</code><span><a class="mark" href="#http2sessionoriginset" id="http…
1113 …illa.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a> |…
1115 <p>If the <code>Http2Session</code> is connected to a <code>TLSSocket</code>, the <code>originSet</…
1116 will return an <code>Array</code> of origins for which the <code>Http2Session</code> may be
1118 <p>The <code>originSet</code> property is only available when using a secure TLS connection.</p>
1119 …code>http2session.pendingSettingsAck</code><span><a class="mark" href="#http2sessionpendingsetting…
1124 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1126 <p>Indicates whether the <code>Http2Session</code> is currently waiting for acknowledgment of
1127 a sent <code>SETTINGS</code> frame. Will be <code>true</code> after calling the
1128 <code>http2session.settings()</code> method. Will be <code>false</code> once all sent <code>SETTING…
1130 …code>http2session.ping([payload, ]callback)</code><span><a class="mark" href="#http2sessionpingpay…
1136 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1143 …code>payload</code> <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="h…
1144 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1145 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boole…
1147 <p>Sends a <code>PING</code> frame to the connected HTTP/2 peer. A <code>callback</code> function m…
1148 be provided. The method will return <code>true</code> if the <code>PING</code> was sent, <code>fals…
1151 <code>maxOutstandingPings</code> configuration option. The default maximum is 10.</p>
1152 <p>If provided, the <code>payload</code> must be a <code>Buffer</code>, <code>TypedArray</code>, or…
1153 containing 8 bytes of data that will be transmitted with the <code>PING</code> and
1156 be <code>null</code> if the <code>PING</code> was successfully acknowledged, a <code>duration</code…
1158 acknowledgment was received, and a <code>Buffer</code> containing the 8-byte <code>PING</code>
1160 …code class="language-js">session.<span class="hljs-title function_">ping</span>(<span class="hljs-…
1161 <span class="hljs-keyword">if</span> (!err) {
1162 …js-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="h…
1163 …="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span clas…
1165 });</code> <button class="copy-button">copy</button></pre>
1166 <p>If the <code>payload</code> argument is not specified, the default payload will be the
1167 64-bit timestamp (little endian) marking the start of the <code>PING</code> duration.</p>
1168 <h5><code>http2session.ref()</code><span><a class="mark" href="#http2sessionref" id="http2sessionre…
1172 <p>Calls <a href="net.html#socketref"><code>ref()</code></a> on this <code>Http2Session</code>
1173 instance's underlying <a href="net.html#class-netsocket"><code>net.Socket</code></a>.</p>
1174 …><code>http2session.remoteSettings</code><span><a class="mark" href="#http2sessionremotesettings" …
1179 <li><a href="http2.html#settings-object" class="type"><HTTP/2 Settings Object></a></li>
1181 <p>A prototype-less object describing the current remote settings of this
1182 <code>Http2Session</code>. The remote settings are set by the <em>connected</em> HTTP/2 peer.</p>
1183 …code>http2session.setLocalWindowSize(windowSize)</code><span><a class="mark" href="#http2sessionse…
1188 <li><code>windowSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s…
1191 The <code>windowSize</code> is the total window size to set, not
1193 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1195 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
1196 <span class="hljs-keyword">const</span> expectedWindowSize = <span class="hljs-number">2</span> ** …
1197 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'connect'</span>, <span cla…
1199 <span class="hljs-comment">// Set local window size to be 2 ** 20</span>
1200 session.<span class="hljs-title function_">setLocalWindowSize</span>(expectedWindowSize);
1201 });</code> <button class="copy-button">copy</button></pre>
1202 …code>http2session.setTimeout(msecs, callback)</code><span><a class="mark" href="#http2sessionsetti…
1208 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1215 <li><code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1216 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1219 the <code>Http2Session</code> after <code>msecs</code> milliseconds. The given <code>callback</code…
1220 registered as a listener on the <code>'timeout'</code> event.</p>
1221 <h5><code>http2session.socket</code><span><a class="mark" href="#http2sessionsocket" id="http2sessi…
1226 <li><a href="net.html#class-netsocket" class="type"><net.Socket></a> | <a href="tls.html#class…
1228 <p>Returns a <code>Proxy</code> object that acts as a <code>net.Socket</code> (or <code>tls.TLSSock…
1230 <p><code>destroy</code>, <code>emit</code>, <code>end</code>, <code>pause</code>, <code>read</code>…
1231 an error with code <code>ERR_HTTP2_NO_SOCKET_MANIPULATION</code>. See
1232 <a href="#http2session-and-sockets"><code>Http2Session</code> and Sockets</a> for more information.…
1233 <p><code>setTimeout</code> method will be called on this <code>Http2Session</code>.</p>
1235 <h5><code>http2session.state</code><span><a class="mark" href="#http2sessionstate" id="http2session…
1240 <code>Http2Session</code>.</p>
1242 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Objec…
1244 <li><code>effectiveLocalWindowSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
1245 flow control window size for the <code>Http2Session</code>.</li>
1246 <li><code>effectiveRecvDataLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Java…
1247 that have been received since the last flow control <code>WINDOW_UPDATE</code>.</li>
1248 <li><code>nextStreamID</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data…
1249 next time a new <code>Http2Stream</code> is created by this <code>Http2Session</code>.</li>
1250 <li><code>localWindowSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
1251 send without receiving a <code>WINDOW_UPDATE</code>.</li>
1252 …code>lastProcStreamID</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data…
1253 for which a <code>HEADERS</code> or <code>DATA</code> frame was most recently received.</li>
1254 …code>remoteWindowSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data…
1255 may send without receiving a <code>WINDOW_UPDATE</code>.</li>
1256 <li><code>outboundQueueSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript…
1257 outbound queue for this <code>Http2Session</code>.</li>
1258 <li><code>deflateDynamicTableSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Java…
1260 <li><code>inflateDynamicTableSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Java…
1265 <p>An object describing the current status of this <code>Http2Session</code>.</p>
1266 …code>http2session.settings([settings][, callback])</code><span><a class="mark" href="#http2session…
1272 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1279 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
1280 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1283 …code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_…
1284 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
1285 <li><code>duration</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1289 <p>Updates the current local settings for this <code>Http2Session</code> and sends a new
1290 <code>SETTINGS</code> frame to the connected HTTP/2 peer.</p>
1291 <p>Once called, the <code>http2session.pendingSettingsAck</code> property will be <code>true</code>
1294 <p>The new settings will not become effective until the <code>SETTINGS</code> acknowledgment
1295 is received and the <code>'localSettings'</code> event is emitted. It is possible to send
1296 multiple <code>SETTINGS</code> frames while acknowledgment is still pending.</p>
1297 <h5><code>http2session.type</code><span><a class="mark" href="#http2sessiontype" id="http2sessionty…
1302 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" c…
1304 <p>The <code>http2session.type</code> will be equal to
1305 <code>http2.constants.NGHTTP2_SESSION_SERVER</code> if this <code>Http2Session</code> instance is a
1306 server, and <code>http2.constants.NGHTTP2_SESSION_CLIENT</code> if the instance is a
1308 <h5><code>http2session.unref()</code><span><a class="mark" href="#http2sessionunref" id="http2sessi…
1312 <p>Calls <a href="net.html#socketunref"><code>unref()</code></a> on this <code>Http2Session</code>
1313 instance's underlying <a href="net.html#class-netsocket"><code>net.Socket</code></a>.</p>
1314 …>Class: <code>ServerHttp2Session</code><span><a class="mark" href="#class-serverhttp2session" id="…
1319 <li>Extends: <a href="http2.html#class-http2session" class="type"><Http2Session></a></li>
1321 …code>serverhttp2session.altsvc(alt, originOrStream)</code><span><a class="mark" href="#serverhttp2…
1326 <li><code>alt</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
1328 …code>originOrStream</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s…
1329 the origin (or an <code>Object</code> with an <code>origin</code> property) or the numeric
1330 identifier of an active <code>Http2Stream</code> as given by the <code>http2stream.id</code>
1333 <p>Submits an <code>ALTSVC</code> frame (as defined by <a href="https://tools.ietf.org/html/rfc7838…
1334 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1336 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
1337 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'session'</span>, <span cla…
1338 <span class="hljs-comment">// Set altsvc for origin https://example.org:80</span>
1339 …session.<span class="hljs-title function_">altsvc</span>(<span class="hljs-string">'h2=":8000"'</s…
1342 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
1343 <span class="hljs-comment">// Set altsvc for a specific stream</span>
1344 …ljs-property">session</span>.<span class="hljs-title function_">altsvc</span>(<span class="hljs-st…
1345 });</code> <button class="copy-button">copy</button></pre>
1346 <p>Sending an <code>ALTSVC</code> frame with a specific stream ID indicates that the alternate
1347 service is associated with the origin of the given <code>Http2Stream</code>.</p>
1348 <p>The <code>alt</code> and origin string <em>must</em> contain only ASCII bytes and are
1349 strictly interpreted as a sequence of ASCII bytes. The special value <code>'clear'</code>
1352 <p>When a string is passed for the <code>originOrStream</code> argument, it will be parsed as
1354 HTTP URL <code>'https://example.org/foo/bar'</code> is the ASCII string
1355 <code>'https://example.org'</code>. An error will be thrown if either the given string
1357 <p>A <code>URL</code> object, or any object with an <code>origin</code> property, may be passed as
1358 <code>originOrStream</code>, in which case the value of the <code>origin</code> property will be
1359 used. The value of the <code>origin</code> property <em>must</em> be a properly serialized
1361 …an><a class="mark" href="#specifying-alternative-services" id="specifying-alternative-services">#<…
1362 <p>The format of the <code>alt</code> parameter is strictly defined by <a href="https://tools.ietf.…
1363 ASCII string containing a comma-delimited list of "alternative" protocols
1365 <p>For example, the value <code>'h2="example.org:81"'</code> indicates that the HTTP/2
1366 protocol is available on the host <code>'example.org'</code> on TCP/IP port 81. The
1367 host and port <em>must</em> be contained within the quote (<code>"</code>) characters.</p>
1368 …Multiple alternatives may be specified, for instance: <code>'h2="example.org:81", h2=":82"'</code>…
1369 <p>The protocol identifier (<code>'h2'</code> in the examples) may be any valid
1370 … href="https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#al…
1373 …code>serverhttp2session.origin(...origins)</code><span><a class="mark" href="#serverhttp2sessionor…
1378 …code>origins</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
1381 <p>Submits an <code>ORIGIN</code> frame (as defined by <a href="https://tools.ietf.org/html/rfc8336…
1384 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1385 <span class="hljs-keyword">const</span> options = <span class="hljs-title function_">getSecureOptio…
1386 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSec…
1387 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
1388 stream.<span class="hljs-title function_">respond</span>();
1389 stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'ok'</span>);
1391 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'session'</span>, <span cla…
1392 …ssion.<span class="hljs-title function_">origin</span>(<span class="hljs-string">'https://example.…
1393 });</code> <button class="copy-button">copy</button></pre>
1394 <p>When a string is passed as an <code>origin</code>, it will be parsed as a URL and the
1396 <code>'https://example.org/foo/bar'</code> is the ASCII string
1397 <code>'https://example.org'</code>. An error will be thrown if either the given string
1399 <p>A <code>URL</code> object, or any object with an <code>origin</code> property, may be passed as
1400 an <code>origin</code>, in which case the value of the <code>origin</code> property will be
1401 used. The value of the <code>origin</code> property <em>must</em> be a properly serialized
1403 <p>Alternatively, the <code>origins</code> option may be used when creating a new HTTP/2
1404 server using the <code>http2.createSecureServer()</code> method:</p>
1405 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1406 <span class="hljs-keyword">const</span> options = <span class="hljs-title function_">getSecureOptio…
1407 options.<span class="hljs-property">origins</span> = [<span class="hljs-string">'https://example.co…
1408 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSec…
1409 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
1410 stream.<span class="hljs-title function_">respond</span>();
1411 stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'ok'</span>);
1412 });</code> <button class="copy-button">copy</button></pre>
1413 …>Class: <code>ClientHttp2Session</code><span><a class="mark" href="#class-clienthttp2session" id="…
1418 <li>Extends: <a href="http2.html#class-http2session" class="type"><Http2Session></a></li>
1420 <h5>Event: <code>'altsvc'</code><span><a class="mark" href="#event-altsvc" id="event-altsvc">#</a><…
1425 <li><code>alt</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
1426 <li><code>origin</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
1427 <li><code>streamId</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1429 <p>The <code>'altsvc'</code> event is emitted whenever an <code>ALTSVC</code> frame is received by
1430 the client. The event is emitted with the <code>ALTSVC</code> value, origin, and stream
1431 ID. If no <code>origin</code> is provided in the <code>ALTSVC</code> frame, <code>origin</code> will
1433 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1434 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
1436 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'altsvc'</span>, <span clas…
1437 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1438 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1439 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1440 });</code> <button class="copy-button">copy</button></pre>
1441 <h5>Event: <code>'origin'</code><span><a class="mark" href="#event-origin" id="event-origin">#</a><…
1446 <li><code>origins</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
1448 <p>The <code>'origin'</code> event is emitted whenever an <code>ORIGIN</code> frame is received by
1449 the client. The event is emitted with an array of <code>origin</code> strings. The
1450 <code>http2session.originSet</code> will be updated to include the received
1452 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1453 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
1455 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'origin'</span>, <span clas…
1456 …ass="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> n = <span class="hljs-number"…
1457 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1458 });</code> <button class="copy-button">copy</button></pre>
1459 <p>The <code>'origin'</code> event is only emitted when using a secure TLS connection.</p>
1460 …code>clienthttp2session.request(headers[, options])</code><span><a class="mark" href="#clienthttp2…
1466 <p><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Objec…
1469 <p><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
1471 …code>endStream</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1472 be closed initially, such as when sending a <code>GET</code> request that should not
1474 …code>exclusive</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1477 <strong>Default:</strong> <code>false</code>.</li>
1478 <li><code>parent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
1480 <li><code>weight</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
1481 to other streams with the same <code>parent</code>. The value is a number between <code>1</code>
1482 and <code>256</code> (inclusive).</li>
1483 …code>waitForTrailers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
1484 <code>'wantTrailers'</code> event after the final <code>DATA</code> frame has been sent.</li>
1485 <li><code>signal</code> <a href="globals.html#class-abortsignal" class="type"><AbortSignal></a…
1490 <p>Returns: <a href="http2.html#class-clienthttp2stream" class="type"><ClientHttp2Stream></a><…
1493 <p>For HTTP/2 Client <code>Http2Session</code> instances only, the <code>http2session.request()</co…
1494 creates and returns an <code>Http2Stream</code> instance that can be used to send an
1496 <p>When a <code>ClientHttp2Session</code> is first created, the socket may not yet be
1497 connected. if <code>clienthttp2session.request()</code> is called during this time, the
1499 If the <code>session</code> is closed before the actual request be executed, an
1500 <code>ERR_HTTP2_GOAWAY_SESSION</code> is thrown.</p>
1501 <p>This method is only available if <code>http2session.type</code> is equal to
1502 <code>http2.constants.NGHTTP2_SESSION_CLIENT</code>.</p>
1503 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1504 <span class="hljs-keyword">const</span> clientSession = http2.<span class="hljs-title function_">co…
1505 <span class="hljs-keyword">const</span> {
1506 <span class="hljs-title class_">HTTP2</span>_HEADER_PATH,
1507 <span class="hljs-title class_">HTTP2</span>_HEADER_STATUS,
1508 } = http2.<span class="hljs-property">constants</span>;
1510 …-keyword">const</span> req = clientSession.<span class="hljs-title function_">request</span>({ [<s…
1511 …span class="hljs-title function_">on</span>(<span class="hljs-string">'response'</span>, <span cla…
1512 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1513 …-title function_">on</span>(<span class="hljs-string">'data'</span>, <span class="hljs-function">(…
1514 … class="hljs-title function_">on</span>(<span class="hljs-string">'end'</span>, <span class="hljs-…
1515 });</code> <button class="copy-button">copy</button></pre>
1516 <p>When the <code>options.waitForTrailers</code> option is set, the <code>'wantTrailers'</code> eve…
1518 The <code>http2stream.sendTrailers()</code> method can then be called to send trailing
1520 <p>When <code>options.waitForTrailers</code> is set, the <code>Http2Stream</code> will not automati…
1521 close when the final <code>DATA</code> frame is transmitted. User code must call either
1522 <code>http2stream.sendTrailers()</code> or <code>http2stream.close()</code> to close the
1523 <code>Http2Stream</code>.</p>
1524 <p>When <code>options.signal</code> is set with an <code>AbortSignal</code> and then <code>abort</c…
1525 corresponding <code>AbortController</code> is called, the request will emit an <code>'error'</code>
1526 event with an <code>AbortError</code> error.</p>
1527 <p>The <code>:method</code> and <code>:path</code> pseudo-headers are not specified within <code>he…
1530 <li><code>:method</code> = <code>'GET'</code></li>
1531 <li><code>:path</code> = <code>/</code></li>
1533 <h4>Class: <code>Http2Stream</code><span><a class="mark" href="#class-http2stream" id="class-http2s…
1538 <li>Extends: <a href="stream.html#class-streamduplex" class="type"><stream.Duplex></a></li>
1540 <p>Each instance of the <code>Http2Stream</code> class represents a bidirectional HTTP/2
1541 communications stream over an <code>Http2Session</code> instance. Any single <code>Http2Session</co…
1542 may have up to 2<sup>31</sup>-1 <code>Http2Stream</code> instances over its lifetime.</p>
1543 <p>User code will not construct <code>Http2Stream</code> instances directly. Rather, these
1544 are created, managed, and provided to user code through the <code>Http2Session</code>
1545 instance. On the server, <code>Http2Stream</code> instances are created either in response
1546 to an incoming HTTP request (and handed off to user code via the <code>'stream'</code>
1547 event), or in response to a call to the <code>http2stream.pushStream()</code> method.
1548 On the client, <code>Http2Stream</code> instances are created and returned when either the
1549 <code>http2session.request()</code> method is called, or in response to an incoming
1550 <code>'push'</code> event.</p>
1551 <p>The <code>Http2Stream</code> class is a base for the <a href="#class-serverhttp2stream"><code>Se…
1552 <a href="#class-clienthttp2stream"><code>ClientHttp2Stream</code></a> classes, each of which is use…
1554 <p>All <code>Http2Stream</code> instances are <a href="stream.html#class-streamduplex"><code>Duplex…
1555 <code>Duplex</code> is used to send data to the connected peer, while the <code>Readable</code> side
1557 <p>The default text character encoding for an <code>Http2Stream</code> is UTF-8. When using an
1558 <code>Http2Stream</code> to send text, use the <code>'content-type'</code> header to set the charac…
1560 <pre><code class="language-js">stream.<span class="hljs-title function_">respond</span>({
1561 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/html; charset=utf…
1562 <span class="hljs-string">':status'</span>: <span class="hljs-number">200</span>,
1563 });</code> <button class="copy-button">copy</button></pre>
1564 <h5><code>Http2Stream</code> Lifecycle<span><a class="mark" href="#http2stream-lifecycle" id="http2…
1565 <h6>Creation<span><a class="mark" href="#creation" id="creation">#</a></span><a aria-hidden="true" …
1566 <p>On the server side, instances of <a href="#class-serverhttp2stream"><code>ServerHttp2Stream</cod…
1569 <li>A new HTTP/2 <code>HEADERS</code> frame with a previously unused stream ID is received;</li>
1570 <li>The <code>http2stream.pushStream()</code> method is called.</li>
1572 <p>On the client side, instances of <a href="#class-clienthttp2stream"><code>ClientHttp2Stream</cod…
1573 <code>http2session.request()</code> method is called.</p>
1574 <p>On the client, the <code>Http2Stream</code> instance returned by <code>http2session.request()</c…
1575 may not be immediately ready for use if the parent <code>Http2Session</code> has not yet
1576 been fully established. In such cases, operations called on the <code>Http2Stream</code>
1577 will be buffered until the <code>'ready'</code> event is emitted. User code should rarely,
1578 if ever, need to handle the <code>'ready'</code> event directly. The ready status of an
1579 <code>Http2Stream</code> can be determined by checking the value of <code>http2stream.id</code>. If
1580 the value is <code>undefined</code>, the stream is not yet ready for use.</p>
1581 <h6>Destruction<span><a class="mark" href="#destruction" id="destruction">#</a></span><a aria-hidde…
1582 <p>All <a href="#class-http2stream"><code>Http2Stream</code></a> instances are destroyed either whe…
1584 <li>An <code>RST_STREAM</code> frame for the stream is received by the connected peer,
1586 <li>The <code>http2stream.close()</code> method is called, and (for client streams only)
1588 <li>The <code>http2stream.destroy()</code> or <code>http2session.destroy()</code> methods are calle…
1590 <p>When an <code>Http2Stream</code> instance is destroyed, an attempt will be made to send an
1591 <code>RST_STREAM</code> frame to the connected peer.</p>
1592 <p>When the <code>Http2Stream</code> instance is destroyed, the <code>'close'</code> event will
1593 be emitted. Because <code>Http2Stream</code> is an instance of <code>stream.Duplex</code>, the
1594 <code>'end'</code> event will also be emitted if the stream data is currently flowing.
1595 The <code>'error'</code> event may also be emitted if <code>http2stream.destroy()</code> was called
1596 with an <code>Error</code> passed as the first argument.</p>
1597 <p>After the <code>Http2Stream</code> has been destroyed, the <code>http2stream.destroyed</code>
1598 property will be <code>true</code> and the <code>http2stream.rstCode</code> property will specify t…
1599 <code>RST_STREAM</code> error code. The <code>Http2Stream</code> instance is no longer usable once
1601 <h5>Event: <code>'aborted'</code><span><a class="mark" href="#event-aborted" id="event-aborted">#</…
1605 <p>The <code>'aborted'</code> event is emitted whenever a <code>Http2Stream</code> instance is
1606 abnormally aborted in mid-communication.
1608 <p>The <code>'aborted'</code> event will only be emitted if the <code>Http2Stream</code> writable s…
1610 <h5>Event: <code>'close'</code><span><a class="mark" href="#event-close_1" id="event-close_1">#</a>…
1614 <p>The <code>'close'</code> event is emitted when the <code>Http2Stream</code> is destroyed. Once
1615 this event is emitted, the <code>Http2Stream</code> instance is no longer usable.</p>
1616 <p>The HTTP/2 error code used when closing the stream can be retrieved using
1617 the <code>http2stream.rstCode</code> property. If the code is any value other than
1618 <code>NGHTTP2_NO_ERROR</code> (<code>0</code>), an <code>'error'</code> event will have also been e…
1619 <h5>Event: <code>'error'</code><span><a class="mark" href="#event-error_1" id="event-error_1">#</a>…
1624 <li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
1626 <p>The <code>'error'</code> event is emitted when an error occurs during the processing of
1627 an <code>Http2Stream</code>.</p>
1628 <h5>Event: <code>'frameError'</code><span><a class="mark" href="#event-frameerror_1" id="event-fram…
1633 <li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
1634 …code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
1635 …code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Nu…
1638 <p>The <code>'frameError'</code> event is emitted when an error occurs while attempting to
1641 error code. The <code>Http2Stream</code> instance will be destroyed immediately after the
1642 <code>'frameError'</code> event is emitted.</p>
1643 <h5>Event: <code>'ready'</code><span><a class="mark" href="#event-ready" id="event-ready">#</a></sp…
1647 <p>The <code>'ready'</code> event is emitted when the <code>Http2Stream</code> has been opened, has
1648 been assigned an <code>id</code>, and can be used. The listener does not expect any
1650 <h5>Event: <code>'timeout'</code><span><a class="mark" href="#event-timeout_1" id="event-timeout_1"…
1654 <p>The <code>'timeout'</code> event is emitted after no activity is received for this
1655 <code>Http2Stream</code> within the number of milliseconds set using
1656 <code>http2stream.setTimeout()</code>.
1658 <h5>Event: <code>'trailers'</code><span><a class="mark" href="#event-trailers" id="event-trailers">…
1663 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
1664 <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1666 <p>The <code>'trailers'</code> event is emitted when a block of headers associated with
1668 <a href="#headers-object">HTTP/2 Headers Object</a> and flags associated with the headers.</p>
1669 <p>This event might not be emitted if <code>http2stream.end()</code> is called
1672 …code class="language-js">stream.<span class="hljs-title function_">on</span>(<span class="hljs-str…
1673 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1674 });</code> <button class="copy-button">copy</button></pre>
1675 <h5>Event: <code>'wantTrailers'</code><span><a class="mark" href="#event-wanttrailers" id="event-wa…
1679 <p>The <code>'wantTrailers'</code> event is emitted when the <code>Http2Stream</code> has queued the
1680 final <code>DATA</code> frame to be sent on a frame and the <code>Http2Stream</code> is ready to se…
1681 trailing headers. When initiating a request or response, the <code>waitForTrailers</code>
1683 <h5><code>http2stream.aborted</code><span><a class="mark" href="#http2streamaborted" id="http2strea…
1688 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1690 <p>Set to <code>true</code> if the <code>Http2Stream</code> instance was aborted abnormally. When s…
1691 the <code>'aborted'</code> event will have been emitted.</p>
1692 <h5><code>http2stream.bufferSize</code><span><a class="mark" href="#http2streambuffersize" id="http…
1697 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" c…
1700 See <a href="net.html#socketbuffersize"><code>net.Socket.bufferSize</code></a> for details.</p>
1701 …code>http2stream.close(code[, callback])</code><span><a class="mark" href="#http2streamclosecode-c…
1707 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1714 …code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
1715 <strong>Default:</strong> <code>http2.constants.NGHTTP2_NO_ERROR</code> (<code>0x00</code>).</li>
1716 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1717 <code>'close'</code> event.</li>
1719 <p>Closes the <code>Http2Stream</code> instance by sending an <code>RST_STREAM</code> frame to the
1721 <h5><code>http2stream.closed</code><span><a class="mark" href="#http2streamclosed" id="http2streamc…
1726 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1728 <p>Set to <code>true</code> if the <code>Http2Stream</code> instance has been closed.</p>
1729 <h5><code>http2stream.destroyed</code><span><a class="mark" href="#http2streamdestroyed" id="http2s…
1734 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1736 <p>Set to <code>true</code> if the <code>Http2Stream</code> instance has been destroyed and is no l…
1738 …><code>http2stream.endAfterHeaders</code><span><a class="mark" href="#http2streamendafterheaders" …
1743 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1745 <p>Set to <code>true</code> if the <code>END_STREAM</code> flag was set in the request or response
1747 and the readable side of the <code>Http2Stream</code> will be closed.</p>
1748 <h5><code>http2stream.id</code><span><a class="mark" href="#http2streamid" id="http2streamid">#</a>…
1753 …zilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | …
1755 <p>The numeric stream identifier of this <code>Http2Stream</code> instance. Set to <code>undefined<…
1757 <h5><code>http2stream.pending</code><span><a class="mark" href="#http2streampending" id="http2strea…
1762 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1764 <p>Set to <code>true</code> if the <code>Http2Stream</code> instance has not yet been assigned a
1766 …<code>http2stream.priority(options)</code><span><a class="mark" href="#http2streampriorityoptions"…
1771 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
1773 …code>exclusive</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1776 <code>false</code>.</li>
1777 <li><code>parent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
1779 <li><code>weight</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
1780 to other streams with the same <code>parent</code>. The value is a number between <code>1</code>
1781 and <code>256</code> (inclusive).</li>
1782 …code>silent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
1783 sending a <code>PRIORITY</code> frame to the connected peer.</li>
1787 <p>Updates the priority for this <code>Http2Stream</code> instance.</p>
1788 <h5><code>http2stream.rstCode</code><span><a class="mark" href="#http2streamrstcode" id="http2strea…
1793 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" c…
1795 …Set to the <code>RST_STREAM</code> <a href="#error-codes-for-rst_stream-and-goaway">error code</a>…
1796 destroyed after either receiving an <code>RST_STREAM</code> frame from the connected peer,
1797 calling <code>http2stream.close()</code>, or <code>http2stream.destroy()</code>. Will be
1798 <code>undefined</code> if the <code>Http2Stream</code> has not been closed.</p>
1799 <h5><code>http2stream.sentHeaders</code><span><a class="mark" href="#http2streamsentheaders" id="ht…
1804 <li><a href="http2.html#headers-object" class="type"><HTTP/2 Headers Object></a></li>
1806 <p>An object containing the outbound headers sent for this <code>Http2Stream</code>.</p>
1807 …><code>http2stream.sentInfoHeaders</code><span><a class="mark" href="#http2streamsentinfoheaders" …
1812 <li><a href="http2.html#headers-object" class="type"><HTTP/2 Headers Object[]></a></li>
1815 sent for this <code>Http2Stream</code>.</p>
1816 <h5><code>http2stream.sentTrailers</code><span><a class="mark" href="#http2streamsenttrailers" id="…
1821 <li><a href="http2.html#headers-object" class="type"><HTTP/2 Headers Object></a></li>
1823 <p>An object containing the outbound trailers sent for this <code>HttpStream</code>.</p>
1824 <h5><code>http2stream.session</code><span><a class="mark" href="#http2streamsession" id="http2strea…
1829 <li><a href="http2.html#class-http2session" class="type"><Http2Session></a></li>
1831 <p>A reference to the <code>Http2Session</code> instance that owns this <code>Http2Stream</code>. T…
1832 value will be <code>undefined</code> after the <code>Http2Stream</code> instance is destroyed.</p>
1833 …code>http2stream.setTimeout(msecs, callback)</code><span><a class="mark" href="#http2streamsettime…
1839 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1846 <li><code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1847 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1849 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1850 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
1851 <span class="hljs-keyword">const</span> { <span class="hljs-title class_">NGHTTP2</span>_CANCEL } =…
1852 …js-keyword">const</span> req = client.<span class="hljs-title function_">request</span>({ <span cl…
1854 <span class="hljs-comment">// Cancel the stream if there's no activity after 5 seconds</span>
1855 …-built_in">setTimeout</span>(<span class="hljs-number">5000</span>, <span class="hljs-function">()…
1856 <h5><code>http2stream.state</code><span><a class="mark" href="#http2streamstate" id="http2streamsta…
1861 <code>Http2Stream</code>.</p>
1863 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Objec…
1865 <li><code>localWindowSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
1866 for this <code>Http2Stream</code> without receiving a <code>WINDOW_UPDATE</code>.</li>
1867 …code>state</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
1868 <code>Http2Stream</code> as determined by <code>nghttp2</code>.</li>
1869 …code>localClose</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
1870 …code>remoteClose</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
1872 …code>sumDependencyWeight</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
1873 instances that depend on this <code>Http2Stream</code> as specified using
1874 <code>PRIORITY</code> frames.</li>
1875 …code>weight</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
1879 <p>A current state of this <code>Http2Stream</code>.</p>
1880 …code>http2stream.sendTrailers(headers)</code><span><a class="mark" href="#http2streamsendtrailersh…
1885 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
1887 <p>Sends a trailing <code>HEADERS</code> frame to the connected HTTP/2 peer. This method
1888 will cause the <code>Http2Stream</code> to be immediately closed and must only be
1889 called after the <code>'wantTrailers'</code> event has been emitted. When sending a
1890 request or sending a response, the <code>options.waitForTrailers</code> option must be set
1891 in order to keep the <code>Http2Stream</code> open after the final <code>DATA</code> frame so that
1893 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1894 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
1895 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
1896 …ljs-title function_">respond</span>(<span class="hljs-literal">undefined</span>, { <span class="hl…
1897 …stream.<span class="hljs-title function_">on</span>(<span class="hljs-string">'wantTrailers'</span…
1898 …stream.<span class="hljs-title function_">sendTrailers</span>({ <span class="hljs-attr">xyz</span>…
1900 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'Hello World'</span…
1901 });</code> <button class="copy-button">copy</button></pre>
1902 <p>The HTTP/1 specification forbids trailers from containing HTTP/2 pseudo-header
1903 fields (e.g. <code>':method'</code>, <code>':path'</code>, etc).</p>
1904 …4>Class: <code>ClientHttp2Stream</code><span><a class="mark" href="#class-clienthttp2stream" id="c…
1909 <li>Extends <a href="http2.html#class-http2stream" class="type"><Http2Stream></a></li>
1911 <p>The <code>ClientHttp2Stream</code> class is an extension of <code>Http2Stream</code> that is
1912 used exclusively on HTTP/2 Clients. <code>Http2Stream</code> instances on the client
1913 provide events such as <code>'response'</code> and <code>'push'</code> that are only relevant on
1915 <h5>Event: <code>'continue'</code><span><a class="mark" href="#event-continue" id="event-continue">…
1919 <p>Emitted when the server sends a <code>100 Continue</code> status, usually because
1920 the request contained <code>Expect: 100-continue</code>. This is an instruction that
1922 <h5>Event: <code>'headers'</code><span><a class="mark" href="#event-headers" id="event-headers">#</…
1927 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
1928 <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1930 <p>The <code>'headers'</code> event is emitted when an additional block of headers is received
1931 for a stream, such as when a block of <code>1xx</code> informational headers is received.
1932 The listener callback is passed the <a href="#headers-object">HTTP/2 Headers Object</a> and flags
1934 …code class="language-js">stream.<span class="hljs-title function_">on</span>(<span class="hljs-str…
1935 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1936 });</code> <button class="copy-button">copy</button></pre>
1937 <h5>Event: <code>'push'</code><span><a class="mark" href="#event-push" id="event-push">#</a></span>…
1942 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
1943 <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1945 <p>The <code>'push'</code> event is emitted when response headers for a Server Push stream
1946 are received. The listener callback is passed the <a href="#headers-object">HTTP/2 Headers Object</…
1948 …code class="language-js">stream.<span class="hljs-title function_">on</span>(<span class="hljs-str…
1949 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1950 });</code> <button class="copy-button">copy</button></pre>
1951 <h5>Event: <code>'response'</code><span><a class="mark" href="#event-response" id="event-response">…
1956 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
1957 <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
1959 <p>The <code>'response'</code> event is emitted when a response <code>HEADERS</code> frame has been
1961 invoked with two arguments: an <code>Object</code> containing the received
1962 <a href="#headers-object">HTTP/2 Headers Object</a>, and flags associated with the headers.</p>
1963 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
1964 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
1965 …js-keyword">const</span> req = client.<span class="hljs-title function_">request</span>({ <span cl…
1966 …span class="hljs-title function_">on</span>(<span class="hljs-string">'response'</span>, <span cla…
1967 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1968 });</code> <button class="copy-button">copy</button></pre>
1969 …4>Class: <code>ServerHttp2Stream</code><span><a class="mark" href="#class-serverhttp2stream" id="c…
1974 <li>Extends: <a href="http2.html#class-http2stream" class="type"><Http2Stream></a></li>
1976 <p>The <code>ServerHttp2Stream</code> class is an extension of <a href="#class-http2stream"><code>H…
1977 used exclusively on HTTP/2 Servers. <code>Http2Stream</code> instances on the server
1978 provide additional methods such as <code>http2stream.pushStream()</code> and
1979 <code>http2stream.respond()</code> that are only relevant on the server.</p>
1980 …code>http2stream.additionalHeaders(headers)</code><span><a class="mark" href="#http2streamaddition…
1985 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
1987 <p>Sends an additional informational <code>HEADERS</code> frame to the connected HTTP/2 peer.</p>
1988 <h5><code>http2stream.headersSent</code><span><a class="mark" href="#http2streamheaderssent" id="ht…
1993 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
1995 <p>True if headers were sent, false otherwise (read-only).</p>
1996 <h5><code>http2stream.pushAllowed</code><span><a class="mark" href="#http2streampushallowed" id="ht…
2001 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
2003 <p>Read-only property mapped to the <code>SETTINGS_ENABLE_PUSH</code> flag of the remote
2004 client's most recent <code>SETTINGS</code> frame. Will be <code>true</code> if the remote peer
2005 accepts push streams, <code>false</code> otherwise. Settings are the same for every
2006 <code>Http2Stream</code> in the same <code>Http2Session</code>.</p>
2007 …code>http2stream.pushStream(headers[, options], callback)</code><span><a class="mark" href="#http2…
2013 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
2020 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
2021 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2023 …code>exclusive</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
2026 <strong>Default:</strong> <code>false</code>.</li>
2027 <li><code>parent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
2031 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
2034 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
2035 …li><code>pushStream</code> <a href="http2.html#class-serverhttp2stream" class="type"><ServerH…
2036 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
2041 <p>Initiates a push stream. The callback is invoked with the new <code>Http2Stream</code>
2043 <code>Error</code> passed as the first argument.</p>
2044 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2045 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2046 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2047 …stream.<span class="hljs-title function_">respond</span>({ <span class="hljs-string">':status'</sp…
2048 …-title function_">pushStream</span>({ <span class="hljs-string">':path'</span>: <span class="hljs-…
2049 <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">throw</span> err;
2050 …pushStream.<span class="hljs-title function_">respond</span>({ <span class="hljs-string">':status'…
2051 …pushStream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'some pushed da…
2053 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'some data'</span>);
2054 });</code> <button class="copy-button">copy</button></pre>
2055 <p>Setting the weight of a push stream is not allowed in the <code>HEADERS</code> frame. Pass
2056 a <code>weight</code> value to <code>http2stream.priority</code> with the <code>silent</code> optio…
2057 <code>true</code> to enable server-side bandwidth balancing between concurrent streams.</p>
2058 <p>Calling <code>http2stream.pushStream()</code> from within a pushed stream is not permitted
2060 …code>http2stream.respond([headers[, options]])</code><span><a class="mark" href="#http2streamrespo…
2073 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
2074 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2076 …code>endStream</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
2078 …code>waitForTrailers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2079 <code>'wantTrailers'</code> event after the final <code>DATA</code> frame has been sent.</li>
2083 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2084 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2085 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2086 …stream.<span class="hljs-title function_">respond</span>({ <span class="hljs-string">':status'</sp…
2087 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'some data'</span>);
2088 });</code> <button class="copy-button">copy</button></pre>
2089 <p>Initiates a response. When the <code>options.waitForTrailers</code> option is set, the
2090 <code>'wantTrailers'</code> event will be emitted immediately after queuing the last chunk
2091 of payload data to be sent. The <code>http2stream.sendTrailers()</code> method can then be
2093 <p>When <code>options.waitForTrailers</code> is set, the <code>Http2Stream</code> will not automati…
2094 close when the final <code>DATA</code> frame is transmitted. User code must call either
2095 <code>http2stream.sendTrailers()</code> or <code>http2stream.close()</code> to close the
2096 <code>Http2Stream</code>.</p>
2097 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2098 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2099 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2100 …-title function_">respond</span>({ <span class="hljs-string">':status'</span>: <span class="hljs-n…
2101 …stream.<span class="hljs-title function_">on</span>(<span class="hljs-string">'wantTrailers'</span…
2102 …stream.<span class="hljs-title function_">sendTrailers</span>({ <span class="hljs-attr">ABC</span>…
2104 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'some data'</span>);
2105 });</code> <button class="copy-button">copy</button></pre>
2106 …code>http2stream.respondWithFD(fd[, headers[, options]])</code><span><a class="mark" href="#http2s…
2114 <td><p>The <code>fd</code> option may now be a <code>FileHandle</code>.</p></td></tr>
2123 …code>fd</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Nu…
2124 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
2125 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2127 <li><code>statCheck</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen…
2128 …code>waitForTrailers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2129 <code>'wantTrailers'</code> event after the final <code>DATA</code> frame has been sent.</li>
2130 <li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
2131 <li><code>length</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
2137 attempting to read data using the file descriptor, the <code>Http2Stream</code> will be
2138 closed using an <code>RST_STREAM</code> frame using the standard <code>INTERNAL_ERROR</code> code.<…
2139 <p>When used, the <code>Http2Stream</code> object's <code>Duplex</code> interface will be closed
2141 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2142 <span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class…
2144 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2145 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2146 …ljs-keyword">const</span> fd = fs.<span class="hljs-title function_">openSync</span>(<span class="…
2148 …<span class="hljs-keyword">const</span> stat = fs.<span class="hljs-title function_">fstatSync</sp…
2149 <span class="hljs-keyword">const</span> headers = {
2150 <span class="hljs-string">'content-length'</span>: stat.<span class="hljs-property">size</span>,
2151 …<span class="hljs-string">'last-modified'</span>: stat.<span class="hljs-property">mtime</span>.<s…
2152 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/plain; charset=ut…
2154 stream.<span class="hljs-title function_">respondWithFD</span>(fd, headers);
2155 …lass="hljs-title function_">on</span>(<span class="hljs-string">'close'</span>, <span class="hljs-…
2156 });</code> <button class="copy-button">copy</button></pre>
2157 <p>The optional <code>options.statCheck</code> function may be specified to give user code
2158 an opportunity to set additional content headers based on the <code>fs.Stat</code> details
2159 of the given fd. If the <code>statCheck</code> function is provided, the
2160 <code>http2stream.respondWithFD()</code> method will perform an <code>fs.fstat()</code> call to
2162 <p>The <code>offset</code> and <code>length</code> options may be used to limit the response to a
2165 <p>The file descriptor or <code>FileHandle</code> is not closed when the stream is closed,
2168 is not supported and may result in data loss. Re-using a file descriptor
2170 <p>When the <code>options.waitForTrailers</code> option is set, the <code>'wantTrailers'</code> eve…
2172 sent. The <code>http2stream.sendTrailers()</code> method can then be used to sent trailing
2174 <p>When <code>options.waitForTrailers</code> is set, the <code>Http2Stream</code> will not automati…
2175 close when the final <code>DATA</code> frame is transmitted. User code <em>must</em> call either
2176 <code>http2stream.sendTrailers()</code> or <code>http2stream.close()</code> to close the
2177 <code>Http2Stream</code>.</p>
2178 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2179 <span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class…
2181 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2182 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2183 …ljs-keyword">const</span> fd = fs.<span class="hljs-title function_">openSync</span>(<span class="…
2185 …<span class="hljs-keyword">const</span> stat = fs.<span class="hljs-title function_">fstatSync</sp…
2186 <span class="hljs-keyword">const</span> headers = {
2187 <span class="hljs-string">'content-length'</span>: stat.<span class="hljs-property">size</span>,
2188 …<span class="hljs-string">'last-modified'</span>: stat.<span class="hljs-property">mtime</span>.<s…
2189 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/plain; charset=ut…
2191 …span class="hljs-title function_">respondWithFD</span>(fd, headers, { <span class="hljs-attr">wait…
2192 …stream.<span class="hljs-title function_">on</span>(<span class="hljs-string">'wantTrailers'</span…
2193 …stream.<span class="hljs-title function_">sendTrailers</span>({ <span class="hljs-attr">ABC</span>…
2196 …lass="hljs-title function_">on</span>(<span class="hljs-string">'close'</span>, <span class="hljs-…
2197 });</code> <button class="copy-button">copy</button></pre>
2198 …code>http2stream.respondWithFile(path[, headers[, options]])</code><span><a class="mark" href="#ht…
2213 …code>path</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
2214 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
2215 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2217 <li><code>statCheck</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen…
2218 <li><code>onError</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2220 …code>waitForTrailers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2221 <code>'wantTrailers'</code> event after the final <code>DATA</code> frame has been sent.</li>
2222 <li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
2223 <li><code>length</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
2227 <p>Sends a regular file as the response. The <code>path</code> must specify a regular file
2228 or an <code>'error'</code> event will be emitted on the <code>Http2Stream</code> object.</p>
2229 <p>When used, the <code>Http2Stream</code> object's <code>Duplex</code> interface will be closed
2231 <p>The optional <code>options.statCheck</code> function may be specified to give user code
2232 an opportunity to set additional content headers based on the <code>fs.Stat</code> details
2234 <p>If an error occurs while attempting to read the file data, the <code>Http2Stream</code>
2235 will be closed using an <code>RST_STREAM</code> frame using the standard <code>INTERNAL_ERROR</code>
2236 code. If the <code>onError</code> callback is defined, then it will be called. Otherwise
2239 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2240 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2241 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2242 …<span class="hljs-keyword">function</span> <span class="hljs-title function_">statCheck</span>(<sp…
2243 …headers[<span class="hljs-string">'last-modified'</span>] = stat.<span class="hljs-property">mtime…
2246 …<span class="hljs-keyword">function</span> <span class="hljs-title function_">onError</span>(<span…
2247 …<span class="hljs-comment">// stream.respond() can throw if the stream has been destroyed by</span>
2248 <span class="hljs-comment">// the other side.</span>
2249 <span class="hljs-keyword">try</span> {
2250 …<span class="hljs-keyword">if</span> (err.<span class="hljs-property">code</span> === <span class=…
2251 …stream.<span class="hljs-title function_">respond</span>({ <span class="hljs-string">':status'</sp…
2252 } <span class="hljs-keyword">else</span> {
2253 …stream.<span class="hljs-title function_">respond</span>({ <span class="hljs-string">':status'</sp…
2255 } <span class="hljs-keyword">catch</span> (err) {
2256 <span class="hljs-comment">// Perform actual error handling.</span>
2257 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</spa…
2259 stream.<span class="hljs-title function_">end</span>();
2262 …stream.<span class="hljs-title function_">respondWithFile</span>(<span class="hljs-string">'/some/…
2263 …{ <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/plain; charset=…
2265 });</code> <button class="copy-button">copy</button></pre>
2266 <p>The <code>options.statCheck</code> function may also be used to cancel the send operation
2267 by returning <code>false</code>. For instance, a conditional request may check the stat
2269 <code>304</code> response:</p>
2270 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2271 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2272 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2273 …<span class="hljs-keyword">function</span> <span class="hljs-title function_">statCheck</span>(<sp…
2274 <span class="hljs-comment">// Check the stat here...</span>
2275 …stream.<span class="hljs-title function_">respond</span>({ <span class="hljs-string">':status'</sp…
2276 …<span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; <span class="hlj…
2278 …stream.<span class="hljs-title function_">respondWithFile</span>(<span class="hljs-string">'/some/…
2279 …{ <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/plain; charset=…
2281 });</code> <button class="copy-button">copy</button></pre>
2282 <p>The <code>content-length</code> header field will be automatically set.</p>
2283 <p>The <code>offset</code> and <code>length</code> options may be used to limit the response to a
2286 <p>The <code>options.onError</code> function may also be used to handle all the errors
2289 <p>When the <code>options.waitForTrailers</code> option is set, the <code>'wantTrailers'</code> eve…
2291 sent. The <code>http2stream.sendTrailers()</code> method can then be used to sent trailing
2293 <p>When <code>options.waitForTrailers</code> is set, the <code>Http2Stream</code> will not automati…
2294 close when the final <code>DATA</code> frame is transmitted. User code must call either
2295 <code>http2stream.sendTrailers()</code> or <code>http2stream.close()</code> to close the
2296 <code>Http2Stream</code>.</p>
2297 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2298 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2299 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2300 …stream.<span class="hljs-title function_">respondWithFile</span>(<span class="hljs-string">'/some/…
2301 …{ <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/plain; charset=…
2302 … { <span class="hljs-attr">waitForTrailers</span>: <span class="hljs-literal">true</span> });
2303 …stream.<span class="hljs-title function_">on</span>(<span class="hljs-string">'wantTrailers'</span…
2304 …stream.<span class="hljs-title function_">sendTrailers</span>({ <span class="hljs-attr">ABC</span>…
2306 });</code> <button class="copy-button">copy</button></pre>
2307 <h4>Class: <code>Http2Server</code><span><a class="mark" href="#class-http2server" id="class-http2s…
2312 <li>Extends: <a href="net.html#class-netserver" class="type"><net.Server></a></li>
2314 <p>Instances of <code>Http2Server</code> are created using the <code>http2.createServer()</code>
2315 function. The <code>Http2Server</code> class is not exported directly by the
2316 <code>node:http2</code> module.</p>
2317 <h5>Event: <code>'checkContinue'</code><span><a class="mark" href="#event-checkcontinue" id="event-…
2322 <li><code>request</code> <a href="http2.html#class-http2http2serverrequest" class="type"><http…
2323 <li><code>response</code> <a href="http2.html#class-http2http2serverresponse" class="type"><ht…
2325 …nt-request"><code>'request'</code></a> listener is registered or <a href="#http2createserveroption…
2326 supplied a callback function, the <code>'checkContinue'</code> event is emitted each time
2327 a request with an HTTP <code>Expect: 100-continue</code> is received. If this event is
2329 <code>100 Continue</code> as appropriate.</p>
2330 …s event involves calling <a href="#responsewritecontinue"><code>response.writeContinue()</code></a…
2334 <p>When this event is emitted and handled, the <a href="#event-request"><code>'request'</code></a> …
2336 <h5>Event: <code>'connection'</code><span><a class="mark" href="#event-connection" id="event-connec…
2341 <li><code>socket</code> <a href="stream.html#class-streamduplex" class="type"><stream.Duplex><…
2343 <p>This event is emitted when a new TCP stream is established. <code>socket</code> is
2344 typically an object of type <a href="net.html#class-netsocket"><code>net.Socket</code></a>. Usually…
2347 into the HTTP server. In that case, any <a href="stream.html#class-streamduplex"><code>Duplex</code…
2348 <h5>Event: <code>'request'</code><span><a class="mark" href="#event-request" id="event-request">#</…
2353 <li><code>request</code> <a href="http2.html#class-http2http2serverrequest" class="type"><http…
2354 <li><code>response</code> <a href="http2.html#class-http2http2serverresponse" class="type"><ht…
2357 per session. See the <a href="#compatibility-api">Compatibility API</a>.</p>
2358 <h5>Event: <code>'session'</code><span><a class="mark" href="#event-session" id="event-session">#</…
2363 <li><code>session</code> <a href="http2.html#class-serverhttp2session" class="type"><ServerHtt…
2365 <p>The <code>'session'</code> event is emitted when a new <code>Http2Session</code> is created by t…
2366 <code>Http2Server</code>.</p>
2367 <h5>Event: <code>'sessionError'</code><span><a class="mark" href="#event-sessionerror" id="event-se…
2372 <li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
2373 <li><code>session</code> <a href="http2.html#class-serverhttp2session" class="type"><ServerHtt…
2375 <p>The <code>'sessionError'</code> event is emitted when an <code>'error'</code> event is emitted by
2376 an <code>Http2Session</code> object associated with the <code>Http2Server</code>.</p>
2377 <h5>Event: <code>'stream'</code><span><a class="mark" href="#event-stream_1" id="event-stream_1">#<…
2382 <li><code>stream</code> <a href="http2.html#class-http2stream" class="type"><Http2Stream></a> …
2383 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
2384 <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
2385 <li><code>rawHeaders</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere…
2388 <p>The <code>'stream'</code> event is emitted when a <code>'stream'</code> event has been emitted by
2389 an <code>Http2Session</code> associated with the server.</p>
2390 <p>See also <a href="#event-stream"><code>Http2Session</code>'s <code>'stream'</code> event</a>.</p>
2391 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2392 <span class="hljs-keyword">const</span> {
2393 <span class="hljs-title class_">HTTP2</span>_HEADER_METHOD,
2394 <span class="hljs-title class_">HTTP2</span>_HEADER_PATH,
2395 <span class="hljs-title class_">HTTP2</span>_HEADER_STATUS,
2396 <span class="hljs-title class_">HTTP2</span>_HEADER_CONTENT_TYPE,
2397 } = http2.<span class="hljs-property">constants</span>;
2399 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2400 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2401 …<span class="hljs-keyword">const</span> method = headers[<span class="hljs-title class_">HTTP2</sp…
2402 …<span class="hljs-keyword">const</span> path = headers[<span class="hljs-title class_">HTTP2</span…
2403 <span class="hljs-comment">// ...</span>
2404 stream.<span class="hljs-title function_">respond</span>({
2405 …[<span class="hljs-title class_">HTTP2</span>_HEADER_STATUS]: <span class="hljs-number">200</span>,
2406 …[<span class="hljs-title class_">HTTP2</span>_HEADER_CONTENT_TYPE]: <span class="hljs-string">'tex…
2408 stream.<span class="hljs-title function_">write</span>(<span class="hljs-string">'hello '</span>);
2409 stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'world'</span>);
2410 });</code> <button class="copy-button">copy</button></pre>
2411 <h5>Event: <code>'timeout'</code><span><a class="mark" href="#event-timeout_2" id="event-timeout_2"…
2423 <p>The <code>'timeout'</code> event is emitted when there is no activity on the Server for
2424 a given number of milliseconds set using <code>http2server.setTimeout()</code>.
2426 <h5><code>server.close([callback])</code><span><a class="mark" href="#serverclosecallback" id="serv…
2431 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
2435 … down the server, call <a href="#http2sessionclosecallback"><code>http2session.close()</code></a> …
2437 <p>If <code>callback</code> is provided, it is not invoked until all active sessions have been
2439 <a href="net.html#serverclosecallback"><code>net.Server.close()</code></a> for more details.</p>
2440 …code>server.setTimeout([msecs][, callback])</code><span><a class="mark" href="#serversettimeoutmse…
2446 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
2455 <li><code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
2456 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
2457 <li>Returns: <a href="http2.html#class-http2server" class="type"><Http2Server></a></li>
2461 on the <code>Http2Server</code> after <code>msecs</code> milliseconds.</p>
2462 <p>The given callback is registered as a listener on the <code>'timeout'</code> event.</p>
2463 <p>In case if <code>callback</code> is not a function, a new <code>ERR_INVALID_ARG_TYPE</code>
2465 <h5><code>server.timeout</code><span><a class="mark" href="#servertimeout" id="servertimeout">#</a>…
2478 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" c…
2482 <p>A value of <code>0</code> will disable the timeout behavior on incoming connections.</p>
2485 …code>server.updateSettings([settings])</code><span><a class="mark" href="#serverupdatesettingssett…
2490 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
2493 <p>Throws <code>ERR_HTTP2_INVALID_SETTING_VALUE</code> for invalid <code>settings</code> values.</p>
2494 <p>Throws <code>ERR_INVALID_ARG_TYPE</code> for invalid <code>settings</code> argument.</p>
2495 …4>Class: <code>Http2SecureServer</code><span><a class="mark" href="#class-http2secureserver" id="c…
2500 <li>Extends: <a href="tls.html#class-tlsserver" class="type"><tls.Server></a></li>
2502 <p>Instances of <code>Http2SecureServer</code> are created using the
2503 <code>http2.createSecureServer()</code> function. The <code>Http2SecureServer</code> class is not
2504 exported directly by the <code>node:http2</code> module.</p>
2505 <h5>Event: <code>'checkContinue'</code><span><a class="mark" href="#event-checkcontinue_1" id="even…
2510 <li><code>request</code> <a href="http2.html#class-http2http2serverrequest" class="type"><http…
2511 <li><code>response</code> <a href="http2.html#class-http2http2serverresponse" class="type"><ht…
2513 …-request"><code>'request'</code></a> listener is registered or <a href="#http2createsecureserverop…
2514 is supplied a callback function, the <code>'checkContinue'</code> event is emitted each
2515 time a request with an HTTP <code>Expect: 100-continue</code> is received. If this event
2517 <code>100 Continue</code> as appropriate.</p>
2518 …s event involves calling <a href="#responsewritecontinue"><code>response.writeContinue()</code></a…
2522 <p>When this event is emitted and handled, the <a href="#event-request"><code>'request'</code></a> …
2524 <h5>Event: <code>'connection'</code><span><a class="mark" href="#event-connection_1" id="event-conn…
2529 <li><code>socket</code> <a href="stream.html#class-streamduplex" class="type"><stream.Duplex><…
2532 handshake begins. <code>socket</code> is typically an object of type <a href="net.html#class-netsoc…
2535 into the HTTP server. In that case, any <a href="stream.html#class-streamduplex"><code>Duplex</code…
2536 <h5>Event: <code>'request'</code><span><a class="mark" href="#event-request_1" id="event-request_1"…
2541 <li><code>request</code> <a href="http2.html#class-http2http2serverrequest" class="type"><http…
2542 <li><code>response</code> <a href="http2.html#class-http2http2serverresponse" class="type"><ht…
2545 per session. See the <a href="#compatibility-api">Compatibility API</a>.</p>
2546 <h5>Event: <code>'session'</code><span><a class="mark" href="#event-session_1" id="event-session_1"…
2551 <li><code>session</code> <a href="http2.html#class-serverhttp2session" class="type"><ServerHtt…
2553 <p>The <code>'session'</code> event is emitted when a new <code>Http2Session</code> is created by t…
2554 <code>Http2SecureServer</code>.</p>
2555 <h5>Event: <code>'sessionError'</code><span><a class="mark" href="#event-sessionerror_1" id="event-…
2560 <li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
2561 <li><code>session</code> <a href="http2.html#class-serverhttp2session" class="type"><ServerHtt…
2563 <p>The <code>'sessionError'</code> event is emitted when an <code>'error'</code> event is emitted by
2564 an <code>Http2Session</code> object associated with the <code>Http2SecureServer</code>.</p>
2565 <h5>Event: <code>'stream'</code><span><a class="mark" href="#event-stream_2" id="event-stream_2">#<…
2570 <li><code>stream</code> <a href="http2.html#class-http2stream" class="type"><Http2Stream></a> …
2571 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
2572 <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
2573 <li><code>rawHeaders</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere…
2576 <p>The <code>'stream'</code> event is emitted when a <code>'stream'</code> event has been emitted by
2577 an <code>Http2Session</code> associated with the server.</p>
2578 <p>See also <a href="#event-stream"><code>Http2Session</code>'s <code>'stream'</code> event</a>.</p>
2579 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2580 <span class="hljs-keyword">const</span> {
2581 <span class="hljs-title class_">HTTP2</span>_HEADER_METHOD,
2582 <span class="hljs-title class_">HTTP2</span>_HEADER_PATH,
2583 <span class="hljs-title class_">HTTP2</span>_HEADER_STATUS,
2584 <span class="hljs-title class_">HTTP2</span>_HEADER_CONTENT_TYPE,
2585 } = http2.<span class="hljs-property">constants</span>;
2587 <span class="hljs-keyword">const</span> options = <span class="hljs-title function_">getOptionsSome…
2589 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSec…
2590 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2591 …<span class="hljs-keyword">const</span> method = headers[<span class="hljs-title class_">HTTP2</sp…
2592 …<span class="hljs-keyword">const</span> path = headers[<span class="hljs-title class_">HTTP2</span…
2593 <span class="hljs-comment">// ...</span>
2594 stream.<span class="hljs-title function_">respond</span>({
2595 …[<span class="hljs-title class_">HTTP2</span>_HEADER_STATUS]: <span class="hljs-number">200</span>,
2596 …[<span class="hljs-title class_">HTTP2</span>_HEADER_CONTENT_TYPE]: <span class="hljs-string">'tex…
2598 stream.<span class="hljs-title function_">write</span>(<span class="hljs-string">'hello '</span>);
2599 stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'world'</span>);
2600 });</code> <button class="copy-button">copy</button></pre>
2601 <h5>Event: <code>'timeout'</code><span><a class="mark" href="#event-timeout_3" id="event-timeout_3"…
2605 <p>The <code>'timeout'</code> event is emitted when there is no activity on the Server for
2606 a given number of milliseconds set using <code>http2secureServer.setTimeout()</code>.
2608 <h5>Event: <code>'unknownProtocol'</code><span><a class="mark" href="#event-unknownprotocol" id="ev…
2613 <li><code>socket</code> <a href="stream.html#class-streamduplex" class="type"><stream.Duplex><…
2615 <p>The <code>'unknownProtocol'</code> event is emitted when a connecting client fails to
2619 <code>'unknownProtocolTimeout'</code> option passed to <a href="#http2createsecureserveroptions-onr…
2620 See the <a href="#compatibility-api">Compatibility API</a>.</p>
2621 <h5><code>server.close([callback])</code><span><a class="mark" href="#serverclosecallback_1" id="se…
2626 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
2630 … down the server, call <a href="#http2sessionclosecallback"><code>http2session.close()</code></a> …
2632 <p>If <code>callback</code> is provided, it is not invoked until all active sessions have been
2634 <a href="tls.html#serverclosecallback"><code>tls.Server.close()</code></a> for more details.</p>
2635 …code>server.setTimeout([msecs][, callback])</code><span><a class="mark" href="#serversettimeoutmse…
2641 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
2648 …code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
2649 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
2650 <li>Returns: <a href="http2.html#class-http2secureserver" class="type"><Http2SecureServer></a>…
2654 on the <code>Http2SecureServer</code> after <code>msecs</code> milliseconds.</p>
2655 <p>The given callback is registered as a listener on the <code>'timeout'</code> event.</p>
2656 <p>In case if <code>callback</code> is not a function, a new <code>ERR_INVALID_ARG_TYPE</code>
2658 <h5><code>server.timeout</code><span><a class="mark" href="#servertimeout_1" id="servertimeout_1">#…
2671 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" c…
2675 <p>A value of <code>0</code> will disable the timeout behavior on incoming connections.</p>
2678 …code>server.updateSettings([settings])</code><span><a class="mark" href="#serverupdatesettingssett…
2683 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
2686 <p>Throws <code>ERR_HTTP2_INVALID_SETTING_VALUE</code> for invalid <code>settings</code> values.</p>
2687 <p>Throws <code>ERR_INVALID_ARG_TYPE</code> for invalid <code>settings</code> argument.</p>
2688 …code>http2.createServer([options][, onRequestHandler])</code><span><a class="mark" href="#http2cre…
2694 …The <code>PADDING_STRATEGY_CALLBACK</code> has been made equivalent to providing <code>PADDING_STR…
2696 <td><p>Added <code>maxSessionRejectedStreams</code> option with a default of 100.</p></td></tr>
2698 <td><p>Added <code>maxSessionInvalidFrames</code> option with a default of 1000.</p></td></tr>
2700 <td><p>The <code>options</code> parameter now supports <code>net.createServer()</code> options.</p>…
2702 <td><p>Added <code>unknownProtocolTimeout</code> option with a default of 10000.</p></td></tr>
2704 <td><p>Added <code>maxSettings</code> option with a default of 32.</p></td></tr>
2706 <td><p>Added the <code>Http1IncomingMessage</code> and <code>Http1ServerResponse</code> option.</p>…
2708 <td><p>Added the <code>maxOutstandingPings</code> option with a default limit of 10.</p></td></tr>
2710 <td><p>Added the <code>maxHeaderListPairs</code> option with a default limit of 128 header pairs.</…
2717 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2719 <li><code>maxDeflateDynamicTableSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/J…
2720 for deflating header fields. <strong>Default:</strong> <code>4Kib</code>.</li>
2721 <li><code>maxSettings</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2722 <code>SETTINGS</code> frame. The minimum value allowed is <code>1</code>. <strong>Default:</strong>…
2723 …code>maxSessionMemory</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2725 e.g. <code>1</code> equal 1 megabyte. The minimum value allowed is <code>1</code>.
2726 This is a credit based limit, existing <code>Http2Stream</code>s may cause this
2727 limit to be exceeded, but new <code>Http2Stream</code> instances will be rejected
2728 while this limit is exceeded. The current number of <code>Http2Stream</code> sessions,
2730 queued to be sent, and unacknowledged <code>PING</code> and <code>SETTINGS</code> frames are all
2731 counted towards the current limit. <strong>Default:</strong> <code>10</code>.</li>
2732 <li><code>maxHeaderListPairs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScrip…
2733 This is similar to <a href="http.html#servermaxheaderscount"><code>server.maxHeadersCount</code></a…
2734 … href="http.html#requestmaxheaderscount"><code>request.maxHeadersCount</code></a> in the <code>nod…
2735 is <code>4</code>. <strong>Default:</strong> <code>128</code>.</li>
2736 <li><code>maxOutstandingPings</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScri…
2737 unacknowledged pings. <strong>Default:</strong> <code>10</code>.</li>
2738 <li><code>maxSendHeaderBlockLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
2740 exceed this limit will result in a <code>'frameError'</code> event being emitted
2743 <code>nghttp2</code> (the internal http2 library) has a limit of <code>65536</code>
2745 <li><code>paddingStrategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
2746 padding to use for <code>HEADERS</code> and <code>DATA</code> frames. <strong>Default:</strong>
2747 <code>http2.constants.PADDING_STRATEGY_NONE</code>. Value may be one of:
2749 <li><code>http2.constants.PADDING_STRATEGY_NONE</code>: No padding is applied.</li>
2750 <li><code>http2.constants.PADDING_STRATEGY_MAX</code>: The maximum amount of padding,
2752 <li><code>http2.constants.PADDING_STRATEGY_ALIGNED</code>: Attempts to apply enough
2753 padding to ensure that the total frame length, including the 9-byte
2761 <li><code>peerMaxConcurrentStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
2762 streams for the remote peer as if a <code>SETTINGS</code> frame had been received. Will
2764 <code>maxConcurrentStreams</code>. <strong>Default:</strong> <code>100</code>.</li>
2765 <li><code>maxSessionInvalidFrames</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Java…
2767 <strong>Default:</strong> <code>1000</code>.</li>
2768 <li><code>maxSessionRejectedStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Ja…
2770 Each rejection is associated with an <code>NGHTTP2_ENHANCE_YOUR_CALM</code>
2773 <strong>Default:</strong> <code>100</code>.</li>
2774 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
2776 <li><code>Http1IncomingMessage</code> <a href="http.html#class-httpincomingmessage" class="type">&#…
2777 <code>IncomingMessage</code> class to used for HTTP/1 fallback. Useful for extending
2778 the original <code>http.IncomingMessage</code>. <strong>Default:</strong> <code>http.IncomingMessag…
2779 …code>Http1ServerResponse</code> <a href="http.html#class-httpserverresponse" class="type"><ht…
2781 <code>http.ServerResponse</code>. <strong>Default:</strong> <code>http.ServerResponse</code>.</li>
2782 <li><code>Http2ServerRequest</code> <a href="http2.html#class-http2http2serverrequest" class="type"…
2783 <code>Http2ServerRequest</code> class to use.
2784 Useful for extending the original <code>Http2ServerRequest</code>.
2785 <strong>Default:</strong> <code>Http2ServerRequest</code>.</li>
2786 <li><code>Http2ServerResponse</code> <a href="http2.html#class-http2http2serverresponse" class="typ…
2787 <code>Http2ServerResponse</code> class to use.
2788 Useful for extending the original <code>Http2ServerResponse</code>.
2789 <strong>Default:</strong> <code>Http2ServerResponse</code>.</li>
2790 <li><code>unknownProtocolTimeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaS…
2791 a server should wait when an <a href="#event-unknownprotocol"><code>'unknownProtocol'</code></a> is…
2793 <strong>Default:</strong> <code>10000</code>.</li>
2794 …i>...: Any <a href="net.html#netcreateserveroptions-connectionlistener"><code>net.createServer()</…
2797 …code>onRequestHandler</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe…
2798 <li>Returns: <a href="http2.html#class-http2server" class="type"><Http2Server></a></li>
2800 <p>Returns a <code>net.Server</code> instance that creates and manages <code>Http2Session</code>
2803 <a href="https://http2.github.io/faq/#does-http2-require-encryption">unencrypted HTTP/2</a>, the us…
2804 <a href="#http2createsecureserveroptions-onrequesthandler"><code>http2.createSecureServer()</code><…
2806 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2808 <span class="hljs-comment">// Create an unencrypted HTTP/2 server.</span>
2809 <span class="hljs-comment">// Since there are no browsers known that support</span>
2810 <span class="hljs-comment">// unencrypted HTTP/2, the use of `http2.createSecureServer()`</span>
2811 <span class="hljs-comment">// is necessary when communicating with browser clients.</span>
2812 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
2814 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2815 stream.<span class="hljs-title function_">respond</span>({
2816 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/html; charset=utf…
2817 <span class="hljs-string">':status'</span>: <span class="hljs-number">200</span>,
2819 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'<h1>Hello Wor…
2822 server.<span class="hljs-title function_">listen</span>(<span class="hljs-number">8000</span>);</co…
2823 …code>http2.createSecureServer(options[, onRequestHandler])</code><span><a class="mark" href="#http…
2829 …The <code>PADDING_STRATEGY_CALLBACK</code> has been made equivalent to providing <code>PADDING_STR…
2831 <td><p>Added <code>maxSessionRejectedStreams</code> option with a default of 100.</p></td></tr>
2833 <td><p>Added <code>maxSessionInvalidFrames</code> option with a default of 1000.</p></td></tr>
2835 <td><p>Added <code>unknownProtocolTimeout</code> option with a default of 10000.</p></td></tr>
2837 <td><p>Added <code>maxSettings</code> option with a default of 32.</p></td></tr>
2839 <td><p>Added the <code>origins</code> option to automatically send an <code>ORIGIN</code> frame on …
2841 <td><p>Added the <code>maxOutstandingPings</code> option with a default limit of 10.</p></td></tr>
2843 <td><p>Added the <code>maxHeaderListPairs</code> option with a default limit of 128 header pairs.</…
2850 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2852 <li><code>allowHTTP1</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s…
2853 HTTP/2 will be downgraded to HTTP/1.x when set to <code>true</code>.
2854 See the <a href="#event-unknownprotocol"><code>'unknownProtocol'</code></a> event. See <a href="#al…
2855 <strong>Default:</strong> <code>false</code>.</li>
2856 <li><code>maxDeflateDynamicTableSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/J…
2857 for deflating header fields. <strong>Default:</strong> <code>4Kib</code>.</li>
2858 <li><code>maxSettings</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2859 <code>SETTINGS</code> frame. The minimum value allowed is <code>1</code>. <strong>Default:</strong>…
2860 …code>maxSessionMemory</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2862 e.g. <code>1</code> equal 1 megabyte. The minimum value allowed is <code>1</code>. This is a
2863 credit based limit, existing <code>Http2Stream</code>s may cause this
2864 limit to be exceeded, but new <code>Http2Stream</code> instances will be rejected
2865 while this limit is exceeded. The current number of <code>Http2Stream</code> sessions,
2867 queued to be sent, and unacknowledged <code>PING</code> and <code>SETTINGS</code> frames are all
2868 counted towards the current limit. <strong>Default:</strong> <code>10</code>.</li>
2869 <li><code>maxHeaderListPairs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScrip…
2870 This is similar to <a href="http.html#servermaxheaderscount"><code>server.maxHeadersCount</code></a…
2871 … href="http.html#requestmaxheaderscount"><code>request.maxHeadersCount</code></a> in the <code>nod…
2872 is <code>4</code>. <strong>Default:</strong> <code>128</code>.</li>
2873 <li><code>maxOutstandingPings</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScri…
2874 unacknowledged pings. <strong>Default:</strong> <code>10</code>.</li>
2875 <li><code>maxSendHeaderBlockLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
2877 exceed this limit will result in a <code>'frameError'</code> event being emitted
2879 <li><code>paddingStrategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
2880 padding to use for <code>HEADERS</code> and <code>DATA</code> frames. <strong>Default:</strong>
2881 <code>http2.constants.PADDING_STRATEGY_NONE</code>. Value may be one of:
2883 <li><code>http2.constants.PADDING_STRATEGY_NONE</code>: No padding is applied.</li>
2884 <li><code>http2.constants.PADDING_STRATEGY_MAX</code>: The maximum amount of padding,
2886 <li><code>http2.constants.PADDING_STRATEGY_ALIGNED</code>: Attempts to apply enough
2888 9-byte header, is a multiple of 8. For each frame, there is a maximum
2895 <li><code>peerMaxConcurrentStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
2896 streams for the remote peer as if a <code>SETTINGS</code> frame had been received. Will
2898 <code>maxConcurrentStreams</code>. <strong>Default:</strong> <code>100</code>.</li>
2899 <li><code>maxSessionInvalidFrames</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Java…
2901 <strong>Default:</strong> <code>1000</code>.</li>
2902 <li><code>maxSessionRejectedStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Ja…
2904 Each rejection is associated with an <code>NGHTTP2_ENHANCE_YOUR_CALM</code>
2907 <strong>Default:</strong> <code>100</code>.</li>
2908 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
2910 …..: Any <a href="tls.html#tlscreateserveroptions-secureconnectionlistener"><code>tls.createServer(…
2911 servers, the identity options (<code>pfx</code> or <code>key</code>/<code>cert</code>) are usually …
2912 …code>origins</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
2913 frame immediately following creation of a new server <code>Http2Session</code>.</li>
2914 <li><code>unknownProtocolTimeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaS…
2915 a server should wait when an <a href="#event-unknownprotocol"><code>'unknownProtocol'</code></a> ev…
2917 <strong>Default:</strong> <code>10000</code>.</li>
2920 …code>onRequestHandler</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe…
2921 <li>Returns: <a href="http2.html#class-http2secureserver" class="type"><Http2SecureServer></a>…
2923 <p>Returns a <code>tls.Server</code> instance that creates and manages <code>Http2Session</code>
2925 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
2926 <span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class…
2928 <span class="hljs-keyword">const</span> options = {
2929 …<span class="hljs-attr">key</span>: fs.<span class="hljs-title function_">readFileSync</span>(<spa…
2930 …<span class="hljs-attr">cert</span>: fs.<span class="hljs-title function_">readFileSync</span>(<sp…
2933 <span class="hljs-comment">// Create a secure HTTP/2 server</span>
2934 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSec…
2936 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
2937 stream.<span class="hljs-title function_">respond</span>({
2938 …<span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text/html; charset=utf…
2939 <span class="hljs-string">':status'</span>: <span class="hljs-number">200</span>,
2941 …stream.<span class="hljs-title function_">end</span>(<span class="hljs-string">'<h1>Hello Wor…
2944 server.<span class="hljs-title function_">listen</span>(<span class="hljs-number">8443</span>);</co…
2945 …code>http2.connect(authority[, options][, listener])</code><span><a class="mark" href="#http2conne…
2951 …The <code>PADDING_STRATEGY_CALLBACK</code> has been made equivalent to providing <code>PADDING_STR…
2953 <td><p>Added <code>unknownProtocolTimeout</code> option with a default of 10000.</p></td></tr>
2955 <td><p>Added <code>maxSettings</code> option with a default of 32.</p></td></tr>
2957 <td><p>Added the <code>maxOutstandingPings</code> option with a default limit of 10.</p></td></tr>
2959 <td><p>Added the <code>maxHeaderListPairs</code> option with a default limit of 128 header pairs.</…
2966 …code>authority</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
2967 be in the form of a minimal, valid URL with the <code>http://</code> or <code>https://</code>
2968 prefix, host name, and IP port (if a non-default port is used). Userinfo
2971 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
2973 <li><code>maxDeflateDynamicTableSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/J…
2974 for deflating header fields. <strong>Default:</strong> <code>4Kib</code>.</li>
2975 <li><code>maxSettings</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2976 <code>SETTINGS</code> frame. The minimum value allowed is <code>1</code>. <strong>Default:</strong>…
2977 …code>maxSessionMemory</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_…
2979 e.g. <code>1</code> equal 1 megabyte. The minimum value allowed is <code>1</code>.
2980 This is a credit based limit, existing <code>Http2Stream</code>s may cause this
2981 limit to be exceeded, but new <code>Http2Stream</code> instances will be rejected
2982 while this limit is exceeded. The current number of <code>Http2Stream</code> sessions,
2984 queued to be sent, and unacknowledged <code>PING</code> and <code>SETTINGS</code> frames are all
2985 counted towards the current limit. <strong>Default:</strong> <code>10</code>.</li>
2986 <li><code>maxHeaderListPairs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScrip…
2987 This is similar to <a href="http.html#servermaxheaderscount"><code>server.maxHeadersCount</code></a…
2988 … href="http.html#requestmaxheaderscount"><code>request.maxHeadersCount</code></a> in the <code>nod…
2989 is <code>1</code>. <strong>Default:</strong> <code>128</code>.</li>
2990 <li><code>maxOutstandingPings</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScri…
2991 unacknowledged pings. <strong>Default:</strong> <code>10</code>.</li>
2992 <li><code>maxReservedRemoteStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
2996 is 0. The maximum allowed value is 2<sup>32</sup>-1. A negative value sets
2997 this option to the maximum allowed value. <strong>Default:</strong> <code>200</code>.</li>
2998 <li><code>maxSendHeaderBlockLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
3000 exceed this limit will result in a <code>'frameError'</code> event being emitted
3002 <li><code>paddingStrategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
3003 padding to use for <code>HEADERS</code> and <code>DATA</code> frames. <strong>Default:</strong>
3004 <code>http2.constants.PADDING_STRATEGY_NONE</code>. Value may be one of:
3006 <li><code>http2.constants.PADDING_STRATEGY_NONE</code>: No padding is applied.</li>
3007 <li><code>http2.constants.PADDING_STRATEGY_MAX</code>: The maximum amount of padding,
3009 <li><code>http2.constants.PADDING_STRATEGY_ALIGNED</code>: Attempts to apply enough
3011 9-byte header, is a multiple of 8. For each frame, there is a maximum
3018 <li><code>peerMaxConcurrentStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/Jav…
3019 streams for the remote peer as if a <code>SETTINGS</code> frame had been received. Will
3021 <code>maxConcurrentStreams</code>. <strong>Default:</strong> <code>100</code>.</li>
3022 <li><code>protocol</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
3023 <code>authority</code>. Value may be either <code>'http:'</code> or <code>'https:'</code>. <strong>…
3024 <code>'https:'</code></li>
3025 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
3027 …code>createConnection</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe…
3028 instance passed to <code>connect</code> and the <code>options</code> object, and returns any
3029 <a href="stream.html#class-streamduplex"><code>Duplex</code></a> stream that is to be used as the c…
3030 …="net.html#netconnect"><code>net.connect()</code></a> or <a href="tls.html#tlsconnectoptions-callb…
3031 <li><code>unknownProtocolTimeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaS…
3032 a server should wait when an <a href="#event-unknownprotocol"><code>'unknownProtocol'</code></a> ev…
3034 <strong>Default:</strong> <code>10000</code>.</li>
3037 …code>listener</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl…
3038 <a href="#event-connect"><code>'connect'</code></a> event.</li>
3039 <li>Returns: <a href="http2.html#class-clienthttp2session" class="type"><ClientHttp2Session></…
3041 <p>Returns a <code>ClientHttp2Session</code> instance.</p>
3042 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3043 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
3045 <span class="hljs-comment">/* Use the client */</span>
3047 client.<span class="hljs-title function_">close</span>();</code> <button class="copy-button">copy</…
3048 <h4><code>http2.constants</code><span><a class="mark" href="#http2constants" id="http2constants">#<…
3052 …code>RST_STREAM</code> and <code>GOAWAY</code><span><a class="mark" href="#error-codes-for-rst_str…
3133 …code>0x00</code></td><td>No Error</td><td><code>http2.constants.NGHTTP2_NO_ERROR</code></td></tr><…
3134 <p>The <code>'timeout'</code> event is emitted when there is no activity on the Server for
3135 a given number of milliseconds set using <code>http2server.setTimeout()</code>.</p>
3136 <h4><code>http2.getDefaultSettings()</code><span><a class="mark" href="#http2getdefaultsettings" id…
3141 <li>Returns: <a href="http2.html#settings-object" class="type"><HTTP/2 Settings Object></a></l…
3143 <p>Returns an object containing the default settings for an <code>Http2Session</code>
3146 …code>http2.getPackedSettings([settings])</code><span><a class="mark" href="#http2getpackedsettings…
3151 <li><code>settings</code> <a href="http2.html#settings-object" class="type"><HTTP/2 Settings O…
3152 <li>Returns: <a href="buffer.html#class-buffer" class="type"><Buffer></a></li>
3154 <p>Returns a <code>Buffer</code> instance containing serialized representation of the given
3156 for use with the <code>HTTP2-Settings</code> header field.</p>
3157 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3159 …-keyword">const</span> packed = http2.<span class="hljs-title function_">getPackedSettings</span>(…
3161 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(packed.<span cla…
3162 <span class="hljs-comment">// Prints: AAIAAAAA</span></code> <button class="copy-button">copy</butt…
3163 …code>http2.getUnpackedSettings(buf)</code><span><a class="mark" href="#http2getunpackedsettingsbuf…
3168 <li><code>buf</code> <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="h…
3169 <li>Returns: <a href="http2.html#settings-object" class="type"><HTTP/2 Settings Object></a></l…
3171 <p>Returns a <a href="#settings-object">HTTP/2 Settings Object</a> containing the deserialized sett…
3172 the given <code>Buffer</code> as generated by <code>http2.getPackedSettings()</code>.</p>
3173 <h4><code>http2.sensitiveHeaders</code><span><a class="mark" href="#http2sensitiveheaders" id="http…
3178 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" c…
3182 See <a href="#sensitive-headers">Sensitive headers</a> for more details.</p>
3183 …4>Headers object<span><a class="mark" href="#headers-object" id="headers-object">#</a></span><a ar…
3184 <p>Headers are represented as own-properties on JavaScript objects. The property
3185 keys will be serialized to lower-case. Property values should be strings (if
3186 they are not they will be coerced to strings) or an <code>Array</code> of strings (in order
3188 <pre><code class="language-js"><span class="hljs-keyword">const</span> headers = {
3189 <span class="hljs-string">':status'</span>: <span class="hljs-string">'200'</span>,
3190 <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text-plain'</span>,
3191 …-string">'ABC'</span>: [<span class="hljs-string">'has'</span>, <span class="hljs-string">'more'</…
3194 stream.<span class="hljs-title function_">respond</span>(headers);</code> <button class="copy-butto…
3195 <p>Header objects passed to callback functions will have a <code>null</code> prototype. This
3197 <code>Object.prototype.toString()</code> and <code>Object.prototype.hasOwnProperty()</code> will
3201 <li>The <code>:status</code> header is converted to <code>number</code>.</li>
3202 <li>Duplicates of <code>:status</code>, <code>:method</code>, <code>:authority</code>, <code>:schem…
3203 <code>:protocol</code>, <code>age</code>, <code>authorization</code>, <code>access-control-allow-cr…
3204 <code>access-control-max-age</code>, <code>access-control-request-method</code>, <code>content-enco…
3205 <code>content-language</code>, <code>content-length</code>, <code>content-location</code>, <code>co…
3206 <code>content-range</code>, <code>content-type</code>, <code>date</code>, <code>dnt</code>, <code>e…
3207 <code>host</code>, <code>if-match</code>, <code>if-modified-since</code>, <code>if-none-match</code…
3208 <code>if-unmodified-since</code>, <code>last-modified</code>, <code>location</code>, <code>max-forw…
3209 <code>proxy-authorization</code>, <code>range</code>, <code>referer</code>,<code>retry-after</code>…
3210 <code>upgrade-insecure-requests</code>, <code>user-agent</code> or <code>x-content-type-options</co…
3212 <li><code>set-cookie</code> is always an array. Duplicates are added to the array.</li>
3213 <li>For duplicate <code>cookie</code> headers, the values are joined together with '; '.</li>
3216 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3217 <span class="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createSer…
3218 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
3219 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
3220 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
3221 });</code> <button class="copy-button">copy</button></pre>
3222 …tive headers<span><a class="mark" href="#sensitive-headers" id="sensitive-headers">#</a></span><a …
3226 attacker, for example <code>Cookie</code> or <code>Authorization</code>. To achieve this, add
3227 the header name to the <code>[http2.sensitiveHeaders]</code> property as an array:</p>
3228 <pre><code class="language-js"><span class="hljs-keyword">const</span> headers = {
3229 <span class="hljs-string">':status'</span>: <span class="hljs-string">'200'</span>,
3230 <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'text-plain'</span>,
3231 <span class="hljs-string">'cookie'</span>: <span class="hljs-string">'some-cookie'</span>,
3232 …<span class="hljs-string">'other-sensitive-header'</span>: <span class="hljs-string">'very secret …
3233 …an class="hljs-property">sensitiveHeaders</span>]: [<span class="hljs-string">'cookie'</span>, <sp…
3236 stream.<span class="hljs-title function_">respond</span>(headers);</code> <button class="copy-butto…
3237 <p>For some headers, such as <code>Authorization</code> and short <code>Cookie</code> headers,
3241 …ettings object<span><a class="mark" href="#settings-object" id="settings-object">#</a></span><a ar…
3247 <td><p>The <code>maxConcurrentStreams</code> setting is stricter.</p></td></tr>
3249 <td><p>The <code>maxHeaderListSize</code> setting is now strictly enforced.</p></td></tr>
3255 <p>The <code>http2.getDefaultSettings()</code>, <code>http2.getPackedSettings()</code>,
3256 <code>http2.createServer()</code>, <code>http2.createSecureServer()</code>,
3257 <code>http2session.settings()</code>, <code>http2session.localSettings</code>, and
3258 <code>http2session.remoteSettings</code> APIs either return or receive as input an
3259 object that defines configuration settings for an <code>Http2Session</code> object.
3263 <li><code>headerTableSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
3265 is 2<sup>32</sup>-1. <strong>Default:</strong> <code>4096</code>.</li>
3266 …code>enablePush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
3267 permitted on the <code>Http2Session</code> instances. <strong>Default:</strong> <code>true</code>.<…
3268 <li><code>initialWindowSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript…
3269 bytes for stream-level flow control. The minimum allowed value is 0. The
3270 maximum allowed value is 2<sup>32</sup>-1. <strong>Default:</strong> <code>65535</code>.</li>
3271 <li><code>maxFrameSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data…
3273 2<sup>24</sup>-1. <strong>Default:</strong> <code>16384</code>.</li>
3274 <li><code>maxConcurrentStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScr…
3275 streams permitted on an <code>Http2Session</code>. There is no default value which
3276 implies, at least theoretically, 2<sup>32</sup>-1 streams may be open
3277 concurrently at any given time in an <code>Http2Session</code>. The minimum value
3278 is 0. The maximum allowed value is 2<sup>32</sup>-1. <strong>Default:</strong>
3279 <code>4294967295</code>.</li>
3280 <li><code>maxHeaderListSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript…
3282 maximum allowed value is 2<sup>32</sup>-1. <strong>Default:</strong> <code>65535</code>.</li>
3283 …code>maxHeaderSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_st…
3284 …code>enableConnectProtocol</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/…
3286 meaningful if sent by the server. Once the <code>enableConnectProtocol</code> setting
3287 has been enabled for a given <code>Http2Session</code>, it cannot be disabled.
3288 <strong>Default:</strong> <code>false</code>.</li>
3291 …h4>Error handling<span><a class="mark" href="#error-handling" id="error-handling">#</a></span><a a…
3293 <code>node:http2</code> module:</p>
3295 passed in. These will always be reported by a synchronous <code>throw</code>.</p>
3298 be reported using either a synchronous <code>throw</code> or via an <code>'error'</code> event on
3299 the <code>Http2Stream</code>, <code>Http2Session</code> or HTTP/2 Server objects, depending on where
3302 reported via an <code>'error'</code> event on the <code>Http2Session</code> or HTTP/2 Server object…
3304 These will be reported using either a synchronous <code>throw</code> or via an <code>'error'</code>
3305 event on the <code>Http2Stream</code>, <code>Http2Session</code> or HTTP/2 Server objects, depending
3307 …ref="#invalid-character-handling-in-header-names-and-values" id="invalid-character-handling-in-hea…
3310 <p>Header field names are <em>case-insensitive</em> and are transmitted over the wire
3311 strictly as lower-case strings. The API provided by Node.js allows header
3312 names to be set as mixed-case strings (e.g. <code>Content-Type</code>) but will convert
3313 those to lower-case (e.g. <code>content-type</code>) upon transmission.</p>
3314 <p>Header field-names <em>must only</em> contain one or more of the following ASCII
3315 …code>a</code>-<code>z</code>, <code>A</code>-<code>Z</code>, <code>0</code>-<code>9</code>, <code>…
3316 <code>-</code>, <code>.</code>, <code>^</code>, <code>_</code>, <code>`</code> (backtick), <code>|<…
3320 new-line or carriage return characters and <em>should</em> be limited to US-ASCII
3322 …lient<span><a class="mark" href="#push-streams-on-the-client" id="push-streams-on-the-client">#</a…
3323 <p>To receive pushed streams on the client, set a listener for the <code>'stream'</code>
3324 event on the <code>ClientHttp2Session</code>:</p>
3325 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3327 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
3329 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
3330 ….<span class="hljs-title function_">on</span>(<span class="hljs-string">'push'</span>, <span class…
3331 <span class="hljs-comment">// Process response headers</span>
3333 …-title function_">on</span>(<span class="hljs-string">'data'</span>, <span class="hljs-function">(…
3336 …-keyword">const</span> req = client.<span class="hljs-title function_">request</span>({ <span clas…
3337 … the <code>CONNECT</code> method<span><a class="mark" href="#supporting-the-connect-method" id="su…
3338 <p>The <code>CONNECT</code> method is used to allow an HTTP/2 server to be used as a proxy
3341 <pre><code class="language-js"><span class="hljs-keyword">const</span> net = <span class="hljs-buil…
3343 …s="hljs-keyword">const</span> server = net.<span class="hljs-title function_">createServer</span>(…
3344 <span class="hljs-keyword">let</span> name = <span class="hljs-string">''</span>;
3345 …socket.<span class="hljs-title function_">setEncoding</span>(<span class="hljs-string">'utf8'</spa…
3346 ….<span class="hljs-title function_">on</span>(<span class="hljs-string">'data'</span>, <span class…
3347 …-title function_">on</span>(<span class="hljs-string">'end'</span>, <span class="hljs-function">()…
3350 server.<span class="hljs-title function_">listen</span>(<span class="hljs-number">8000</span>);</co…
3352 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3353 <span class="hljs-keyword">const</span> { <span class="hljs-title class_">NGHTTP2</span>_REFUSED_ST…
3354 <span class="hljs-keyword">const</span> net = <span class="hljs-built_in">require</span>(<span clas…
3356 <span class="hljs-keyword">const</span> proxy = http2.<span class="hljs-title function_">createServ…
3357 …<span class="hljs-title function_">on</span>(<span class="hljs-string">'stream'</span>, <span clas…
3358 …<span class="hljs-keyword">if</span> (headers[<span class="hljs-string">':method'</span>] !== <spa…
3359 <span class="hljs-comment">// Only accept CONNECT requests</span>
3360 …stream.<span class="hljs-title function_">close</span>(<span class="hljs-title class_">NGHTTP2</sp…
3361 <span class="hljs-keyword">return</span>;
3363 …-keyword">const</span> auth = <span class="hljs-keyword">new</span> <span class="hljs-title functi…
3364 <span class="hljs-comment">// It's a very good idea to verify that hostname and port are</span>
3365 <span class="hljs-comment">// things this proxy should be connecting to.</span>
3366 …-keyword">const</span> socket = net.<span class="hljs-title function_">connect</span>(auth.<span c…
3367 stream.<span class="hljs-title function_">respond</span>();
3368 socket.<span class="hljs-title function_">pipe</span>(stream);
3369 stream.<span class="hljs-title function_">pipe</span>(socket);
3371 ….<span class="hljs-title function_">on</span>(<span class="hljs-string">'error'</span>, <span clas…
3372 …stream.<span class="hljs-title function_">close</span>(http2.<span class="hljs-property">constants…
3376 proxy.<span class="hljs-title function_">listen</span>(<span class="hljs-number">8001</span>);</cod…
3378 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3380 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
3382 <span class="hljs-comment">// Must not specify the ':path' and ':scheme' headers</span>
3383 <span class="hljs-comment">// for CONNECT requests or an error will be thrown.</span>
3384 <span class="hljs-keyword">const</span> req = client.<span class="hljs-title function_">request</sp…
3385 <span class="hljs-string">':method'</span>: <span class="hljs-string">'CONNECT'</span>,
3386 <span class="hljs-string">':authority'</span>: <span class="hljs-string">'localhost:8000'</span>,
3389 …span class="hljs-title function_">on</span>(<span class="hljs-string">'response'</span>, <span cla…
3390 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(headers[http2.<s…
3392 <span class="hljs-keyword">let</span> data = <span class="hljs-string">''</span>;
3393 req.<span class="hljs-title function_">setEncoding</span>(<span class="hljs-string">'utf8'</span>);
3394 ….<span class="hljs-title function_">on</span>(<span class="hljs-string">'data'</span>, <span class…
3395 req.<span class="hljs-title function_">on</span>(<span class="hljs-string">'end'</span>, <span clas…
3396 …hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class=…
3397 client.<span class="hljs-title function_">close</span>();
3399 req.<span class="hljs-title function_">end</span>(<span class="hljs-string">'Jane'</span>);</code> …
3400 …ded <code>CONNECT</code> protocol<span><a class="mark" href="#the-extended-connect-protocol" id="t…
3402 may be used to bootstrap the use of an <code>Http2Stream</code> using the <code>CONNECT</code>
3405 the <code>enableConnectProtocol</code> setting:</p>
3406 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3407 <span class="hljs-keyword">const</span> settings = { <span class="hljs-attr">enableConnectProtocol<…
3408 …ass="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createServer</sp…
3409 <p>Once the client receives the <code>SETTINGS</code> frame from the server indicating that
3410 the extended CONNECT may be used, it may send <code>CONNECT</code> requests that use the
3411 <code>':protocol'</code> HTTP/2 pseudo-header:</p>
3412 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3413 <span class="hljs-keyword">const</span> client = http2.<span class="hljs-title function_">connect</…
3414 …n class="hljs-title function_">on</span>(<span class="hljs-string">'remoteSettings'</span>, <span …
3415 …<span class="hljs-keyword">if</span> (settings.<span class="hljs-property">enableConnectProtocol</…
3416 …-keyword">const</span> req = client.<span class="hljs-title function_">request</span>({ <span clas…
3417 <span class="hljs-comment">// ...</span>
3419 });</code> <button class="copy-button">copy</button></pre>
3420 …bility API<span><a class="mark" href="#compatibility-api" id="compatibility-api">#</a></span><a ar…
3429 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3430 …="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createServer</span>…
3431 …res.<span class="hljs-title function_">setHeader</span>(<span class="hljs-string">'Content-Type'</…
3432 …res.<span class="hljs-title function_">setHeader</span>(<span class="hljs-string">'X-Foo'</span>, …
3433 …-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-strin…
3434 res.<span class="hljs-title function_">end</span>(<span class="hljs-string">'ok'</span>);
3435 });</code> <button class="copy-button">copy</button></pre>
3437 <a href="#alpn-negotiation">ALPN negotiation</a> section.
3438 Upgrading from non-tls HTTP/1 servers is not supported.</p>
3439 …compatibility API is composed of <a href="#class-http2http2serverrequest"><code>Http2ServerRequest…
3440 <a href="#class-http2http2serverresponse"><code>Http2ServerResponse</code></a>. They aim at API com…
3443 …LPN negotiation<span><a class="mark" href="#alpn-negotiation" id="alpn-negotiation">#</a></span><a…
3445 the same socket. The <code>req</code> and <code>res</code> objects can be either HTTP/1 or
3450 …<code class="language-js"><span class="hljs-keyword">const</span> { createSecureServer } = <span c…
3451 <span class="hljs-keyword">const</span> { readFileSync } = <span class="hljs-built_in">require</spa…
3453 <span class="hljs-keyword">const</span> cert = <span class="hljs-title function_">readFileSync</spa…
3454 <span class="hljs-keyword">const</span> key = <span class="hljs-title function_">readFileSync</span…
3456 <span class="hljs-keyword">const</span> server = <span class="hljs-title function_">createSecureSer…
3457 { cert, key, <span class="hljs-attr">allowHTTP1</span>: <span class="hljs-literal">true</span> },
3459 ).<span class="hljs-title function_">listen</span>(<span class="hljs-number">4443</span>);
3461 <span class="hljs-keyword">function</span> <span class="hljs-title function_">onRequest</span>(<spa…
3462 <span class="hljs-comment">// Detects if it is a HTTPS request or HTTP/2</span>
3463 …-keyword">const</span> { <span class="hljs-attr">socket</span>: { alpnProtocol } } = req.<span cla…
3464 req.<span class="hljs-property">stream</span>.<span class="hljs-property">session</span> : req;
3465 …"hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-…
3466 …res.<span class="hljs-title function_">end</span>(<span class="hljs-title class_">JSON</span>.<spa…
3468 <span class="hljs-attr">httpVersion</span>: req.<span class="hljs-property">httpVersion</span>,
3470 }</code> <button class="copy-button">copy</button></pre>
3471 <p>The <code>'request'</code> event works identically on both <a href="https.html">HTTPS</a> and
3473 …<code>http2.Http2ServerRequest</code><span><a class="mark" href="#class-http2http2serverrequest" i…
3478 <li>Extends: <a href="stream.html#class-streamreadable" class="type"><stream.Readable></a></li>
3480 <p>A <code>Http2ServerRequest</code> object is created by <a href="#class-http2server"><code>http2.…
3481 <a href="#class-http2secureserver"><code>http2.SecureServer</code></a> and passed as the first argu…
3482 <a href="#event-request"><code>'request'</code></a> event. It may be used to access a request statu…
3484 <h5>Event: <code>'aborted'</code><span><a class="mark" href="#event-aborted_1" id="event-aborted_1"…
3488 <p>The <code>'aborted'</code> event is emitted whenever a <code>Http2ServerRequest</code> instance …
3489 abnormally aborted in mid-communication.</p>
3490 <p>The <code>'aborted'</code> event will only be emitted if the <code>Http2ServerRequest</code> wri…
3492 <h5>Event: <code>'close'</code><span><a class="mark" href="#event-close_2" id="event-close_2">#</a>…
3496 <p>Indicates that the underlying <a href="#class-http2stream"><code>Http2Stream</code></a> was clos…
3497 Just like <code>'end'</code>, this event occurs only once per response.</p>
3498 <h5><code>request.aborted</code><span><a class="mark" href="#requestaborted" id="requestaborted">#<…
3503 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
3505 <p>The <code>request.aborted</code> property will be <code>true</code> if the request has
3507 <h5><code>request.authority</code><span><a class="mark" href="#requestauthority" id="requestauthori…
3512 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
3515 to set either <code>:authority</code> or <code>host</code>, this value is derived from
3516 <code>req.headers[':authority']</code> if present. Otherwise, it is derived from
3517 <code>req.headers['host']</code>.</p>
3518 <h5><code>request.complete</code><span><a class="mark" href="#requestcomplete" id="requestcomplete"…
3523 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
3525 <p>The <code>request.complete</code> property will be <code>true</code> if the request has
3527 <h5><code>request.connection</code><span><a class="mark" href="#requestconnection" id="requestconne…
3531 …"documentation.html#stability-index">Stability: 0</a> - Deprecated. Use <a href="#requestsocket"><…
3533 <li><a href="net.html#class-netsocket" class="type"><net.Socket></a> | <a href="tls.html#class…
3535 <p>See <a href="#requestsocket"><code>request.socket</code></a>.</p>
3536 <h5><code>request.destroy([error])</code><span><a class="mark" href="#requestdestroyerror" id="requ…
3541 <li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
3543 <p>Calls <code>destroy()</code> on the <a href="#class-http2stream"><code>Http2Stream</code></a> th…
3544 … <a href="#class-http2http2serverrequest"><code>Http2ServerRequest</code></a>. If <code>error</cod…
3545 is emitted and <code>error</code> is passed as an argument to any listeners on the event.</p>
3547 <h5><code>request.headers</code><span><a class="mark" href="#requestheaders" id="requestheaders">#<…
3552 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Objec…
3555 <p>Key-value pairs of header names and values. Header names are lower-cased.</p>
3556 <pre><code class="language-js"><span class="hljs-comment">// Prints something like:</span>
3557 <span class="hljs-comment">//</span>
3558 <span class="hljs-comment">// { 'user-agent': 'curl/7.22.0',</span>
3559 <span class="hljs-comment">// host: '127.0.0.1:8000',</span>
3560 <span class="hljs-comment">// accept: '*/*' }</span>
3561 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(request.<span cl…
3562 <p>See <a href="#headers-object">HTTP/2 Headers Object</a>.</p>
3564 special headers prefixed with the <code>:</code> character (e.g. <code>':path'</code>). These speci…
3565 headers will be included in the <code>request.headers</code> object. Care must be taken not
3568 <pre><code class="language-js"><span class="hljs-title function_">removeAllHeaders</span>(request.<…
3569 …-title function_">assert</span>(request.<span class="hljs-property">url</span>); <span class="hl…
3570 <h5><code>request.httpVersion</code><span><a class="mark" href="#requesthttpversion" id="requesthtt…
3575 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
3578 client response, the HTTP version of the connected-to server. Returns
3579 <code>'2.0'</code>.</p>
3580 <p>Also <code>message.httpVersionMajor</code> is the first integer and
3581 <code>message.httpVersionMinor</code> is the second.</p>
3582 <h5><code>request.method</code><span><a class="mark" href="#requestmethod" id="requestmethod">#</a>…
3587 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
3589 <p>The request method as a string. Read-only. Examples: <code>'GET'</code>, <code>'DELETE'</code>.<…
3590 <h5><code>request.rawHeaders</code><span><a class="mark" href="#requestrawheaders" id="requestrawhe…
3595 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
3599 list of tuples. So, the even-numbered offsets are key values, and the
3600 odd-numbered offsets are the associated values.</p>
3602 <pre><code class="language-js"><span class="hljs-comment">// Prints something like:</span>
3603 <span class="hljs-comment">//</span>
3604 <span class="hljs-comment">// [ 'user-agent',</span>
3605 <span class="hljs-comment">// 'this is invalid because there can be only one',</span>
3606 <span class="hljs-comment">// 'User-Agent',</span>
3607 <span class="hljs-comment">// 'curl/7.22.0',</span>
3608 <span class="hljs-comment">// 'Host',</span>
3609 <span class="hljs-comment">// '127.0.0.1:8000',</span>
3610 <span class="hljs-comment">// 'ACCEPT',</span>
3611 <span class="hljs-comment">// '*/*' ]</span>
3612 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(request.<span cl…
3613 <h5><code>request.rawTrailers</code><span><a class="mark" href="#requestrawtrailers" id="requestraw…
3618 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
3621 received. Only populated at the <code>'end'</code> event.</p>
3622 <h5><code>request.scheme</code><span><a class="mark" href="#requestscheme" id="requestscheme">#</a>…
3627 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
3631 …code>request.setTimeout(msecs, callback)</code><span><a class="mark" href="#requestsettimeoutmsecs…
3636 <li><code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
3637 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
3638 <li>Returns: <a href="http2.html#class-http2http2serverrequest" class="type"><http2.Http2Serve…
3640 <p>Sets the <a href="#class-http2stream"><code>Http2Stream</code></a>'s timeout value to <code>msec…
3641 provided, then it is added as a listener on the <code>'timeout'</code> event on
3643 <p>If no <code>'timeout'</code> listener is added to the request, the response, or
3644 the server, then <a href="#class-http2stream"><code>Http2Stream</code></a>s are destroyed when they…
3645 handler is assigned to the request, the response, or the server's <code>'timeout'</code>
3647 <h5><code>request.socket</code><span><a class="mark" href="#requestsocket" id="requestsocket">#</a>…
3652 <li><a href="net.html#class-netsocket" class="type"><net.Socket></a> | <a href="tls.html#class…
3654 <p>Returns a <code>Proxy</code> object that acts as a <code>net.Socket</code> (or <code>tls.TLSSock…
3656 <p><code>destroyed</code>, <code>readable</code>, and <code>writable</code> properties will be retr…
3657 set on <code>request.stream</code>.</p>
3658 <p><code>destroy</code>, <code>emit</code>, <code>end</code>, <code>on</code> and <code>once</code>…
3659 <code>request.stream</code>.</p>
3660 <p><code>setTimeout</code> method will be called on <code>request.stream.session</code>.</p>
3661 <p><code>pause</code>, <code>read</code>, <code>resume</code>, and <code>write</code> will throw an…
3662 <code>ERR_HTTP2_NO_SOCKET_MANIPULATION</code>. See <a href="#http2session-and-sockets"><code>Http2S…
3665 …href="tls.html#tlssocketgetpeercertificatedetailed"><code>request.socket.getPeerCertificate()</cod…
3667 <h5><code>request.stream</code><span><a class="mark" href="#requeststream" id="requeststream">#</a>…
3672 <li><a href="http2.html#class-http2stream" class="type"><Http2Stream></a></li>
3674 <p>The <a href="#class-http2stream"><code>Http2Stream</code></a> object backing the request.</p>
3675 <h5><code>request.trailers</code><span><a class="mark" href="#requesttrailers" id="requesttrailers"…
3680 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Objec…
3682 <p>The request/response trailers object. Only populated at the <code>'end'</code> event.</p>
3683 <h5><code>request.url</code><span><a class="mark" href="#requesturl" id="requesturl">#</a></span><a…
3688 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
3692 <pre><code class="language-http"><span class="hljs-keyword">GET</span> <span class="hljs-string">/s…
3693 <span class="hljs-attribute">Accept</span><span class="hljs-punctuation">: </span>text/plain</code>…
3694 <p>Then <code>request.url</code> will be:</p>
3695 <!-- eslint-disable semi -->
3696 <pre><code class="language-js"><span class="hljs-string">'/status?name=ryan'</span></code> <button …
3697 <p>To parse the url into its parts, <code>new URL()</code> can be used:</p>
3698 <pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-…
3699 …lass="hljs-meta prompt_">> </span><span class="language-bash">new URL(<span class="hljs-string">'/…
3713 }</code> <button class="copy-button">copy</button></pre>
3714 …code>http2.Http2ServerResponse</code><span><a class="mark" href="#class-http2http2serverresponse" …
3722 passed as the second parameter to the <a href="#event-request"><code>'request'</code></a> event.</p>
3723 <h5>Event: <code>'close'</code><span><a class="mark" href="#event-close_3" id="event-close_3">#</a>…
3727 <p>Indicates that the underlying <a href="#class-http2stream"><code>Http2Stream</code></a> was term…
3728 <a href="#responseenddata-encoding-callback"><code>response.end()</code></a> was called or able to …
3729 <h5>Event: <code>'finish'</code><span><a class="mark" href="#event-finish" id="event-finish">#</a><…
3738 …<code>response.addTrailers(headers)</code><span><a class="mark" href="#responseaddtrailersheaders"…
3743 <li><code>headers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
3748 will result in a <a href="errors.html#class-typeerror"><code>TypeError</code></a> being thrown.</p>
3749 <h5><code>response.connection</code><span><a class="mark" href="#responseconnection" id="responseco…
3753 …documentation.html#stability-index">Stability: 0</a> - Deprecated. Use <a href="#responsesocket"><…
3755 <li><a href="net.html#class-netsocket" class="type"><net.Socket></a> | <a href="tls.html#class…
3757 <p>See <a href="#responsesocket"><code>response.socket</code></a>.</p>
3758 …code>response.createPushResponse(headers, callback)</code><span><a class="mark" href="#responsecre…
3764 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
3771 <li><code>headers</code> <a href="http2.html#headers-object" class="type"><HTTP/2 Headers Obje…
3772 …code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl…
3773 or either when the attempt to create the pushed <code>Http2Stream</code> has failed or
3774 has been rejected, or the state of <code>Http2ServerRequest</code> is closed prior to
3775 calling the <code>http2stream.pushStream()</code> method
3777 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
3778 …code>res</code> <a href="http2.html#class-http2http2serverresponse" class="type"><http2.Http2…
3783 <p>Call <a href="#http2streampushstreamheaders-options-callback"><code>http2stream.pushStream()</co…
3784 given <a href="#class-http2stream"><code>Http2Stream</code></a> on a newly created <code>Http2Serve…
3785 parameter if successful. When <code>Http2ServerRequest</code> is closed, the callback is
3786 called with an error <code>ERR_HTTP2_INVALID_STREAM</code>.</p>
3787 …code>response.end([data[, encoding]][, callback])</code><span><a class="mark" href="#responseendda…
3793 <td><p>This method now returns a reference to <code>ServerResponse</code>.</p></td></tr>
3800 …code>data</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
3801 <li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
3802 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
3803 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/t…
3807 The method, <code>response.end()</code>, MUST be called on each response.</p>
3808 <p>If <code>data</code> is specified, it is equivalent to calling
3809 …#responsewritechunk-encoding-callback"><code>response.write(data, encoding)</code></a> followed by…
3810 <p>If <code>callback</code> is specified, it will be called when the response stream
3812 <h5><code>response.finished</code><span><a class="mark" href="#responsefinished" id="responsefinish…
3816 …tation.html#stability-index">Stability: 0</a> - Deprecated. Use <a href="#responsewritableended"><…
3818 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
3821 …s <code>false</code>. After <a href="#responseenddata-encoding-callback"><code>response.end()</cod…
3822 <h5><code>response.getHeader(name)</code><span><a class="mark" href="#responsegetheadername" id="re…
3827 <li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
3828 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Strin…
3831 The name is case-insensitive.</p>
3832 …code class="language-js"><span class="hljs-keyword">const</span> contentType = response.<span clas…
3833 <h5><code>response.getHeaderNames()</code><span><a class="mark" href="#responsegetheadernames" id="…
3838 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Strin…
3842 …re><code class="language-js">response.<span class="hljs-title function_">setHeader</span>(<span cl…
3843 …hljs-title function_">setHeader</span>(<span class="hljs-string">'Set-Cookie'</span>, [<span class…
3845 <span class="hljs-keyword">const</span> headerNames = response.<span class="hljs-title function_">g…
3846 <span class="hljs-comment">// headerNames === ['foo', 'set-cookie']</span></code> <button class="co…
3847 <h5><code>response.getHeaders()</code><span><a class="mark" href="#responsegetheaders" id="response…
3852 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obje…
3856 header-related http module methods. The keys of the returned object are the
3859 <p>The object returned by the <code>response.getHeaders()</code> method <em>does not</em>
3860 prototypically inherit from the JavaScript <code>Object</code>. This means that typical
3861 <code>Object</code> methods such as <code>obj.toString()</code>, <code>obj.hasOwnProperty()</code>,…
3863 …re><code class="language-js">response.<span class="hljs-title function_">setHeader</span>(<span cl…
3864 …hljs-title function_">setHeader</span>(<span class="hljs-string">'Set-Cookie'</span>, [<span class…
3866 <span class="hljs-keyword">const</span> headers = response.<span class="hljs-title function_">getHe…
3867 <span class="hljs-comment">// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }</spa…
3868 <h5><code>response.hasHeader(name)</code><span><a class="mark" href="#responsehasheadername" id="re…
3873 <li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
3874 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boole…
3876 <p>Returns <code>true</code> if the header identified by <code>name</code> is currently set in the
3877 outgoing headers. The header name matching is case-insensitive.</p>
3878 …code class="language-js"><span class="hljs-keyword">const</span> hasContentType = response.<span c…
3879 <h5><code>response.headersSent</code><span><a class="mark" href="#responseheaderssent" id="response…
3884 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
3886 <p>True if headers were sent, false otherwise (read-only).</p>
3887 …h5><code>response.removeHeader(name)</code><span><a class="mark" href="#responseremoveheadername" …
3892 <li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
3895 …code class="language-js">response.<span class="hljs-title function_">removeHeader</span>(<span cla…
3896 <h5><code>response.req</code><span><a class="mark" href="#responsereq" id="responsereq">#</a></span…
3901 <li><a href="http2.html#class-http2http2serverrequest" class="type"><http2.Http2ServerRequest>…
3903 <p>A reference to the original HTTP2 <code>request</code> object.</p>
3904 <h5><code>response.sendDate</code><span><a class="mark" href="#responsesenddate" id="responsesendda…
3909 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
3915 …code>response.setHeader(name, value)</code><span><a class="mark" href="#responsesetheadername-valu…
3920 <li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
3921 …code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
3924 in the to-be-sent headers, its value will be replaced. Use an array of strings
3926 …code class="language-js">response.<span class="hljs-title function_">setHeader</span>(<span class=…
3928 …code class="language-js">response.<span class="hljs-title function_">setHeader</span>(<span class=…
3930 will result in a <a href="errors.html#class-typeerror"><code>TypeError</code></a> being thrown.</p>
3931 …aders have been set with <a href="#responsesetheadername-value"><code>response.setHeader()</code><…
3932 … passed to <a href="#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead()…
3933 to <a href="#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead()</code></…
3934 <pre><code class="language-js"><span class="hljs-comment">// Returns content-type = text/plain</spa…
3935 …="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createServer</span>…
3936 …ass="hljs-title function_">setHeader</span>(<span class="hljs-string">'Content-Type'</span>, <span…
3937 …res.<span class="hljs-title function_">setHeader</span>(<span class="hljs-string">'X-Foo'</span>, …
3938 …-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-strin…
3939 res.<span class="hljs-title function_">end</span>(<span class="hljs-string">'ok'</span>);
3940 });</code> <button class="copy-button">copy</button></pre>
3941 …code>response.setTimeout(msecs[, callback])</code><span><a class="mark" href="#responsesettimeoutm…
3946 <li><code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
3947 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
3948 <li>Returns: <a href="http2.html#class-http2http2serverresponse" class="type"><http2.Http2Serv…
3950 <p>Sets the <a href="#class-http2stream"><code>Http2Stream</code></a>'s timeout value to <code>msec…
3951 provided, then it is added as a listener on the <code>'timeout'</code> event on
3953 <p>If no <code>'timeout'</code> listener is added to the request, the response, or
3954 the server, then <a href="#class-http2stream"><code>Http2Stream</code></a>s are destroyed when they…
3955 handler is assigned to the request, the response, or the server's <code>'timeout'</code>
3957 <h5><code>response.socket</code><span><a class="mark" href="#responsesocket" id="responsesocket">#<…
3962 <li><a href="net.html#class-netsocket" class="type"><net.Socket></a> | <a href="tls.html#class…
3964 <p>Returns a <code>Proxy</code> object that acts as a <code>net.Socket</code> (or <code>tls.TLSSock…
3966 <p><code>destroyed</code>, <code>readable</code>, and <code>writable</code> properties will be retr…
3967 set on <code>response.stream</code>.</p>
3968 <p><code>destroy</code>, <code>emit</code>, <code>end</code>, <code>on</code> and <code>once</code>…
3969 <code>response.stream</code>.</p>
3970 <p><code>setTimeout</code> method will be called on <code>response.stream.session</code>.</p>
3971 <p><code>pause</code>, <code>read</code>, <code>resume</code>, and <code>write</code> will throw an…
3972 <code>ERR_HTTP2_NO_SOCKET_MANIPULATION</code>. See <a href="#http2session-and-sockets"><code>Http2S…
3975 <pre><code class="language-js"><span class="hljs-keyword">const</span> http2 = <span class="hljs-bu…
3976 …="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createServer</span>…
3977 …<span class="hljs-keyword">const</span> ip = req.<span class="hljs-property">socket</span>.<span c…
3978 …<span class="hljs-keyword">const</span> port = req.<span class="hljs-property">socket</span>.<span…
3979 …-title function_">end</span>(<span class="hljs-string">`Your IP address is <span class="hljs-subst…
3980 }).<span class="hljs-title function_">listen</span>(<span class="hljs-number">3000</span>);</code> …
3981 <h5><code>response.statusCode</code><span><a class="mark" href="#responsestatuscode" id="responsest…
3986 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" c…
3988 …ot calling <a href="#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead()…
3989 this property controls the status code that will be sent to the client when
3991 …e><code class="language-js">response.<span class="hljs-property">statusCode</span> = <span class="…
3993 status code which was sent out.</p>
3994 <h5><code>response.statusMessage</code><span><a class="mark" href="#responsestatusmessage" id="resp…
3999 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" c…
4003 <h5><code>response.stream</code><span><a class="mark" href="#responsestream" id="responsestream">#<…
4008 <li><a href="http2.html#class-http2stream" class="type"><Http2Stream></a></li>
4010 <p>The <a href="#class-http2stream"><code>Http2Stream</code></a> object backing the response.</p>
4011 <h5><code>response.writableEnded</code><span><a class="mark" href="#responsewritableended" id="resp…
4016 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" …
4018 <p>Is <code>true</code> after <a href="#responseenddata-encoding-callback"><code>response.end()</co…
4020 <a href="stream.html#writablewritablefinished"><code>writable.writableFinished</code></a> instead.<…
4021 …code>response.write(chunk[, encoding][, callback])</code><span><a class="mark" href="#responsewrit…
4026 …code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
4027 <li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
4028 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
4029 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boole…
4031 …called and <a href="#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead()…
4035 <p>In the <code>node:http</code> module, the response body is omitted when the
4036 request is a HEAD request. Similarly, the <code>204</code> and <code>304</code> responses
4038 <p><code>chunk</code> can be a string or a buffer. If <code>chunk</code> is a string,
4040 By default the <code>encoding</code> is <code>'utf8'</code>. <code>callback</code> will be called w…
4042 <p>This is the raw HTTP body and has nothing to do with higher-level multi-part
4044 <p>The first time <a href="#responsewritechunk-encoding-callback"><code>response.write()</code></a>…
4046 time <a href="#responsewritechunk-encoding-callback"><code>response.write()</code></a> is called, N…
4049 <p>Returns <code>true</code> if the entire data was flushed successfully to the kernel
4050 buffer. Returns <code>false</code> if all or part of the data was queued in user memory.
4051 <code>'drain'</code> will be emitted when the buffer is free again.</p>
4052 <h5><code>response.writeContinue()</code><span><a class="mark" href="#responsewritecontinue" id="re…
4056 <p>Sends a status <code>100 Continue</code> to the client, indicating that the request body
4057 …uld be sent. See the <a href="#event-checkcontinue"><code>'checkContinue'</code></a> event on <cod…
4058 <code>Http2SecureServer</code>.</p>
4059 …code>response.writeEarlyHints(hints)</code><span><a class="mark" href="#responsewriteearlyhintshin…
4064 <li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
4066 <p>Sends a status <code>103 Early Hints</code> to the client with a Link header,
4068 The <code>hints</code> is an object containing the values of headers to be sent with
4071 <pre><code class="language-js"><span class="hljs-keyword">const</span> earlyHintsLink = <span class…
4072 response.<span class="hljs-title function_">writeEarlyHints</span>({
4073 <span class="hljs-string">'link'</span>: earlyHintsLink,
4076 <span class="hljs-keyword">const</span> earlyHintsLinks = [
4077 <span class="hljs-string">'</styles.css>; rel=preload; as=style'</span>,
4078 <span class="hljs-string">'</scripts.js>; rel=preload; as=script'</span>,
4080 response.<span class="hljs-title function_">writeEarlyHints</span>({
4081 <span class="hljs-string">'link'</span>: earlyHintsLinks,
4082 });</code> <button class="copy-button">copy</button></pre>
4083 …code>response.writeHead(statusCode[, statusMessage][, headers])</code><span><a class="mark" href="…
4089 <td><p>Return <code>this</code> from <code>writeHead()</code> to allow chaining with <code>end()</c…
4096 <li><code>statusCode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s…
4097 <li><code>statusMessage</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Dat…
4098 …code>headers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
4099 <li>Returns: <a href="http2.html#class-http2http2serverresponse" class="type"><http2.Http2Serv…
4101 <p>Sends a response header to the request. The status code is a 3-digit HTTP
4102 status code, like <code>404</code>. The last argument, <code>headers</code>, are the response heade…
4103 <p>Returns a reference to the <code>Http2ServerResponse</code>, so that calls can be chained.</p>
4104 … compatibility with <a href="http.html">HTTP/1</a>, a human-readable <code>statusMessage</code> ma…
4105 passed as the second argument. However, because the <code>statusMessage</code> has no
4108 <pre><code class="language-js"><span class="hljs-keyword">const</span> body = <span class="hljs-str…
4109 response.<span class="hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, {
4110 …<span class="hljs-string">'Content-Length'</span>: <span class="hljs-title class_">Buffer</span>.<…
4111 …<span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'text/plain; charset=ut…
4112 });</code> <button class="copy-button">copy</button></pre>
4113 <p><code>Content-Length</code> is given in bytes not characters. The
4114 <code>Buffer.byteLength()</code> API may be used to determine the number of bytes in a
4115 given encoding. On outbound messages, Node.js does not check if Content-Length
4118 <code>Content-Length</code> does not match the actual payload size.</p>
4120 <a href="#responseenddata-encoding-callback"><code>response.end()</code></a> is called.</p>
4121 …sewritechunk-encoding-callback"><code>response.write()</code></a> or <a href="#responseenddata-enc…
4123 …aders have been set with <a href="#responsesetheadername-value"><code>response.setHeader()</code><…
4124 … passed to <a href="#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead()…
4125 to <a href="#responsewriteheadstatuscode-statusmessage-headers"><code>response.writeHead()</code></…
4126 <pre><code class="language-js"><span class="hljs-comment">// Returns content-type = text/plain</spa…
4127 …="hljs-keyword">const</span> server = http2.<span class="hljs-title function_">createServer</span>…
4128 …ass="hljs-title function_">setHeader</span>(<span class="hljs-string">'Content-Type'</span>, <span…
4129 …res.<span class="hljs-title function_">setHeader</span>(<span class="hljs-string">'X-Foo'</span>, …
4130 …-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-strin…
4131 res.<span class="hljs-title function_">end</span>(<span class="hljs-string">'ok'</span>);
4132 });</code> <button class="copy-button">copy</button></pre>
4134 will result in a <a href="errors.html#class-typeerror"><code>TypeError</code></a> being thrown.</p>
4135 … class="mark" href="#collecting-http2-performance-metrics" id="collecting-http2-performance-metric…
4137 metrics for each <code>Http2Session</code> and <code>Http2Stream</code> instance.</p>
4138 …code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_"…
4140 …-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_"…
4141 …<span class="hljs-keyword">const</span> entry = items.<span class="hljs-title function_">getEntrie…
4142 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(entry.<span clas…
4143 …<span class="hljs-keyword">if</span> (entry.<span class="hljs-property">name</span> === <span clas…
4144 <span class="hljs-comment">// Entry contains statistics about the Http2Session</span>
4145 … class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (entry.<span class="hljs-pr…
4146 <span class="hljs-comment">// Entry contains statistics about the Http2Stream</span>
4149 …-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-s…
4150 <p>The <code>entryType</code> property of the <code>PerformanceEntry</code> will be equal to <code>…
4151 <p>The <code>name</code> property of the <code>PerformanceEntry</code> will be equal to either
4152 <code>'Http2Stream'</code> or <code>'Http2Session'</code>.</p>
4153 <p>If <code>name</code> is equal to <code>Http2Stream</code>, the <code>PerformanceEntry</code> wil…
4156 …code>bytesRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
4157 <code>Http2Stream</code>.</li>
4158 …code>bytesWritten</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
4159 <code>Http2Stream</code>.</li>
4160 …code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Nu…
4161 <li><code>timeToFirstByte</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/D…
4162 <code>PerformanceEntry</code> <code>startTime</code> and the reception of the first <code>DATA</cod…
4163 <li><code>timeToFirstByteSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScri…
4164 the <code>PerformanceEntry</code> <code>startTime</code> and sending of the first <code>DATA</code>…
4165 <li><code>timeToFirstHeader</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript…
4166 <code>PerformanceEntry</code> <code>startTime</code> and the reception of the first header.</li>
4168 <p>If <code>name</code> is equal to <code>Http2Session</code>, the <code>PerformanceEntry</code> wi…
4171 …code>bytesRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
4172 …code>bytesWritten</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
4173 <li><code>framesReceived</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Da…
4174 <code>Http2Session</code>.</li>
4175 …code>framesSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struc…
4176 <li><code>maxConcurrentStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScr…
4177 open during the lifetime of the <code>Http2Session</code>.</li>
4178 <li><code>pingRTT</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
4179 of a <code>PING</code> frame and the reception of its acknowledgment. Only present if
4180 a <code>PING</code> frame has been sent on the <code>Http2Session</code>.</li>
4181 <li><code>streamAverageDuration</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaSc…
4182 all <code>Http2Stream</code> instances.</li>
4183 …code>streamCount</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
4184 the <code>Http2Session</code>.</li>
4185 …code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#…
4186 <code>Http2Session</code>.</li>
4188 …code>:authority</code> and <code>host</code><span><a class="mark" href="#note-on-authority-and-hos…
4189 <p>HTTP/2 requires requests to have either the <code>:authority</code> pseudo-header
4190 or the <code>host</code> header. Prefer <code>:authority</code> when constructing an HTTP/2
4191 request directly, and <code>host</code> when converting from HTTP/1 (in proxies,
4193 <p>The compatibility API falls back to <code>host</code> if <code>:authority</code> is not
4194 present. See <a href="#requestauthority"><code>request.authority</code></a> for more information. H…
4195 if you don't use the compatibility API (or use <code>req.headers</code> directly),
4196 you need to implement any fall-back behavior yourself.</p></section>
4197 <!-- API END -->