-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp2.json
More file actions
3449 lines (3449 loc) · 242 KB
/
http2.json
File metadata and controls
3449 lines (3449 loc) · 242 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"type": "module",
"source": "doc/api/http2.md",
"modules": [
{
"textRaw": "HTTP/2",
"name": "http/2",
"meta": {
"added": [
"v8.4.0"
],
"changes": [
{
"version": "v10.10.0",
"pr-url": "https://github.com/nodejs/node/pull/22466",
"description": "HTTP/2 is now Stable. Previously, it had been Experimental."
}
]
},
"introduced_in": "v8.4.0",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>The <code>http2</code> module provides an implementation of the <a href=\"https://tools.ietf.org/html/rfc7540\">HTTP/2</a> protocol. It\ncan be accessed using:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\n</code></pre>",
"modules": [
{
"textRaw": "Core API",
"name": "core_api",
"desc": "<p>The Core API provides a low-level interface designed specifically around\nsupport for HTTP/2 protocol features. It is specifically <em>not</em> designed for\ncompatibility with the existing <a href=\"http.html\">HTTP/1</a> module API. However,\nthe <a href=\"#http2_compatibility_api\">Compatibility API</a> is.</p>\n<p>The <code>http2</code> Core API is much more symmetric between client and server than the\n<code>http</code> API. For instance, most events, like <code>'error'</code>, <code>'connect'</code> and\n<code>'stream'</code>, can be emitted either by client-side code or server-side code.</p>",
"modules": [
{
"textRaw": "Server-side example",
"name": "server-side_example",
"desc": "<p>The following illustrates a simple HTTP/2 server using the Core API.\nSince there are no browsers known that support\n<a href=\"https://http2.github.io/faq/#does-http2-require-encryption\">unencrypted HTTP/2</a>, the use of\n<a href=\"#http2_http2_createsecureserver_options_onrequesthandler\"><code>http2.createSecureServer()</code></a> is necessary when communicating\nwith browser clients.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst fs = require('fs');\n\nconst server = http2.createSecureServer({\n key: fs.readFileSync('localhost-privkey.pem'),\n cert: fs.readFileSync('localhost-cert.pem')\n});\nserver.on('error', (err) => console.error(err));\n\nserver.on('stream', (stream, headers) => {\n // stream is a Duplex\n stream.respond({\n 'content-type': 'text/html',\n ':status': 200\n });\n stream.end('<h1>Hello World</h1>');\n});\n\nserver.listen(8443);\n</code></pre>\n<p>To generate the certificate and key for this example, run:</p>\n<pre><code class=\"language-bash\">openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \\\n -keyout localhost-privkey.pem -out localhost-cert.pem\n</code></pre>",
"type": "module",
"displayName": "Server-side example"
},
{
"textRaw": "Client-side example",
"name": "client-side_example",
"desc": "<p>The following illustrates an HTTP/2 client:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst fs = require('fs');\nconst client = http2.connect('https://localhost:8443', {\n ca: fs.readFileSync('localhost-cert.pem')\n});\nclient.on('error', (err) => console.error(err));\n\nconst req = client.request({ ':path': '/' });\n\nreq.on('response', (headers, flags) => {\n for (const name in headers) {\n console.log(`${name}: ${headers[name]}`);\n }\n});\n\nreq.setEncoding('utf8');\nlet data = '';\nreq.on('data', (chunk) => { data += chunk; });\nreq.on('end', () => {\n console.log(`\\n${data}`);\n client.close();\n});\nreq.end();\n</code></pre>",
"type": "module",
"displayName": "Client-side example"
},
{
"textRaw": "Headers Object",
"name": "headers_object",
"desc": "<p>Headers are represented as own-properties on JavaScript objects. The property\nkeys will be serialized to lower-case. Property values should be strings (if\nthey are not they will be coerced to strings) or an <code>Array</code> of strings (in order\nto send more than one value per header field).</p>\n<pre><code class=\"language-js\">const headers = {\n ':status': '200',\n 'content-type': 'text-plain',\n 'ABC': ['has', 'more', 'than', 'one', 'value']\n};\n\nstream.respond(headers);\n</code></pre>\n<p>Header objects passed to callback functions will have a <code>null</code> prototype. This\nmeans that normal JavaScript object methods such as\n<code>Object.prototype.toString()</code> and <code>Object.prototype.hasOwnProperty()</code> will\nnot work.</p>\n<p>For incoming headers:</p>\n<ul>\n<li>The <code>:status</code> header is converted to <code>number</code>.</li>\n<li>Duplicates of <code>:status</code>, <code>:method</code>, <code>:authority</code>, <code>:scheme</code>, <code>:path</code>,\n<code>:protocol</code>, <code>age</code>, <code>authorization</code>, <code>access-control-allow-credentials</code>,\n<code>access-control-max-age</code>, <code>access-control-request-method</code>, <code>content-encoding</code>,\n<code>content-language</code>, <code>content-length</code>, <code>content-location</code>, <code>content-md5</code>,\n<code>content-range</code>, <code>content-type</code>, <code>date</code>, <code>dnt</code>, <code>etag</code>, <code>expires</code>, <code>from</code>,\n<code>if-match</code>, <code>if-modified-since</code>, <code>if-none-match</code>, <code>if-range</code>,\n<code>if-unmodified-since</code>, <code>last-modified</code>, <code>location</code>, <code>max-forwards</code>,\n<code>proxy-authorization</code>, <code>range</code>, <code>referer</code>,<code>retry-after</code>, <code>tk</code>,\n<code>upgrade-insecure-requests</code>, <code>user-agent</code> or <code>x-content-type-options</code> are\ndiscarded.</li>\n<li><code>set-cookie</code> is always an array. Duplicates are added to the array.</li>\n<li><code>cookie</code>: the values are joined together with '; '.</li>\n<li>For all other headers, the values are joined together with ', '.</li>\n</ul>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst server = http2.createServer();\nserver.on('stream', (stream, headers) => {\n console.log(headers[':path']);\n console.log(headers.ABC);\n});\n</code></pre>",
"type": "module",
"displayName": "Headers Object"
},
{
"textRaw": "Settings Object",
"name": "settings_object",
"meta": {
"added": [
"v8.4.0"
],
"changes": [
{
"version": "v8.9.3",
"pr-url": "https://github.com/nodejs/node/pull/16676",
"description": "The `maxHeaderListSize` setting is now strictly enforced."
}
]
},
"desc": "<p>The <code>http2.getDefaultSettings()</code>, <code>http2.getPackedSettings()</code>,\n<code>http2.createServer()</code>, <code>http2.createSecureServer()</code>,\n<code>http2session.settings()</code>, <code>http2session.localSettings</code>, and\n<code>http2session.remoteSettings</code> APIs either return or receive as input an\nobject that defines configuration settings for an <code>Http2Session</code> object.\nThese objects are ordinary JavaScript objects containing the following\nproperties.</p>\n<ul>\n<li><code>headerTableSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> Specifies the maximum number of bytes used for\nheader compression. The minimum allowed value is 0. The maximum allowed value\nis 2<sup>32</sup>-1. <strong>Default:</strong> <code>4,096 octets</code>.</li>\n<li><code>enablePush</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\"><boolean></a> Specifies <code>true</code> if HTTP/2 Push Streams are to be\npermitted on the <code>Http2Session</code> instances.</li>\n<li><code>initialWindowSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> Specifies the <em>senders</em> initial window size\nfor stream-level flow control. The minimum allowed value is 0. The maximum\nallowed value is 2<sup>32</sup>-1. <strong>Default:</strong> <code>65,535 bytes</code>.</li>\n<li><code>maxFrameSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> Specifies the size of the largest frame payload.\nThe minimum allowed value is 16,384. The maximum allowed value\nis 2<sup>24</sup>-1. <strong>Default:</strong> <code>16,384 bytes</code>.</li>\n<li><code>maxConcurrentStreams</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> Specifies the maximum number of concurrent\nstreams permitted on an <code>Http2Session</code>. There is no default value which\nimplies, at least theoretically, 2<sup>31</sup>-1 streams may be open\nconcurrently at any given time in an <code>Http2Session</code>. The minimum value\nis 0. The maximum allowed value is 2<sup>31</sup>-1.</li>\n<li><code>maxHeaderListSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> Specifies the maximum size (uncompressed octets)\nof header list that will be accepted. The minimum allowed value is 0. The\nmaximum allowed value is 2<sup>32</sup>-1. <strong>Default:</strong> <code>65535</code>.</li>\n<li><code>enableConnectProtocol</code><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\"><boolean></a> Specifies <code>true</code> if the \"Extended Connect\nProtocol\" defined by <a href=\"https://tools.ietf.org/html/rfc8441\">RFC 8441</a> is to be enabled. This setting is only\nmeaningful if sent by the server. Once the <code>enableConnectProtocol</code> setting\nhas been enabled for a given <code>Http2Session</code>, it cannot be disabled.</li>\n</ul>\n<p>All additional properties on the settings object are ignored.</p>",
"type": "module",
"displayName": "Settings Object"
},
{
"textRaw": "Using `options.selectPadding()`",
"name": "using_`options.selectpadding()`",
"desc": "<p>When <code>options.paddingStrategy</code> is equal to\n<code>http2.constants.PADDING_STRATEGY_CALLBACK</code>, the HTTP/2 implementation will\nconsult the <code>options.selectPadding()</code> callback function, if provided, to\ndetermine the specific amount of padding to use per <code>HEADERS</code> and <code>DATA</code> frame.</p>\n<p>The <code>options.selectPadding()</code> function receives two numeric arguments,\n<code>frameLen</code> and <code>maxFrameLen</code> and must return a number <code>N</code> such that\n<code>frameLen <= N <= maxFrameLen</code>.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst server = http2.createServer({\n paddingStrategy: http2.constants.PADDING_STRATEGY_CALLBACK,\n selectPadding(frameLen, maxFrameLen) {\n return maxFrameLen;\n }\n});\n</code></pre>\n<p>The <code>options.selectPadding()</code> function is invoked once for <em>every</em> <code>HEADERS</code> and\n<code>DATA</code> frame. This has a definite noticeable impact on performance.</p>",
"type": "module",
"displayName": "Using `options.selectPadding()`"
},
{
"textRaw": "Error Handling",
"name": "error_handling",
"desc": "<p>There are several types of error conditions that may arise when using the\n<code>http2</code> module:</p>\n<p>Validation errors occur when an incorrect argument, option, or setting value is\npassed in. These will always be reported by a synchronous <code>throw</code>.</p>\n<p>State errors occur when an action is attempted at an incorrect time (for\ninstance, attempting to send data on a stream after it has closed). These will\nbe reported using either a synchronous <code>throw</code> or via an <code>'error'</code> event on\nthe <code>Http2Stream</code>, <code>Http2Session</code> or HTTP/2 Server objects, depending on where\nand when the error occurs.</p>\n<p>Internal errors occur when an HTTP/2 session fails unexpectedly. These will be\nreported via an <code>'error'</code> event on the <code>Http2Session</code> or HTTP/2 Server objects.</p>\n<p>Protocol errors occur when various HTTP/2 protocol constraints are violated.\nThese will be reported using either a synchronous <code>throw</code> or via an <code>'error'</code>\nevent on the <code>Http2Stream</code>, <code>Http2Session</code> or HTTP/2 Server objects, depending\non where and when the error occurs.</p>",
"type": "module",
"displayName": "Error Handling"
},
{
"textRaw": "Invalid character handling in header names and values",
"name": "invalid_character_handling_in_header_names_and_values",
"desc": "<p>The HTTP/2 implementation applies stricter handling of invalid characters in\nHTTP header names and values than the HTTP/1 implementation.</p>\n<p>Header field names are <em>case-insensitive</em> and are transmitted over the wire\nstrictly as lower-case strings. The API provided by Node.js allows header\nnames to be set as mixed-case strings (e.g. <code>Content-Type</code>) but will convert\nthose to lower-case (e.g. <code>content-type</code>) upon transmission.</p>\n<p>Header field-names <em>must only</em> contain one or more of the following ASCII\ncharacters: <code>a</code>-<code>z</code>, <code>A</code>-<code>Z</code>, <code>0</code>-<code>9</code>, <code>!</code>, <code>#</code>, <code>$</code>, <code>%</code>, <code>&</code>, <code>'</code>, <code>*</code>, <code>+</code>,\n<code>-</code>, <code>.</code>, <code>^</code>, <code>_</code>, <code>`</code> (backtick), <code>|</code>, and <code>~</code>.</p>\n<p>Using invalid characters within an HTTP header field name will cause the\nstream to be closed with a protocol error being reported.</p>\n<p>Header field values are handled with more leniency but <em>should</em> not contain\nnew-line or carriage return characters and <em>should</em> be limited to US-ASCII\ncharacters, per the requirements of the HTTP specification.</p>",
"type": "module",
"displayName": "Invalid character handling in header names and values"
},
{
"textRaw": "Push streams on the client",
"name": "push_streams_on_the_client",
"desc": "<p>To receive pushed streams on the client, set a listener for the <code>'stream'</code>\nevent on the <code>ClientHttp2Session</code>:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\n\nconst client = http2.connect('http://localhost');\n\nclient.on('stream', (pushedStream, requestHeaders) => {\n pushedStream.on('push', (responseHeaders) => {\n // process response headers\n });\n pushedStream.on('data', (chunk) => { /* handle pushed data */ });\n});\n\nconst req = client.request({ ':path': '/' });\n</code></pre>",
"type": "module",
"displayName": "Push streams on the client"
},
{
"textRaw": "Supporting the CONNECT method",
"name": "supporting_the_connect_method",
"desc": "<p>The <code>CONNECT</code> method is used to allow an HTTP/2 server to be used as a proxy\nfor TCP/IP connections.</p>\n<p>A simple TCP Server:</p>\n<pre><code class=\"language-js\">const net = require('net');\n\nconst server = net.createServer((socket) => {\n let name = '';\n socket.setEncoding('utf8');\n socket.on('data', (chunk) => name += chunk);\n socket.on('end', () => socket.end(`hello ${name}`));\n});\n\nserver.listen(8000);\n</code></pre>\n<p>An HTTP/2 CONNECT proxy:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst { NGHTTP2_REFUSED_STREAM } = http2.constants;\nconst net = require('net');\n\nconst proxy = http2.createServer();\nproxy.on('stream', (stream, headers) => {\n if (headers[':method'] !== 'CONNECT') {\n // Only accept CONNECT requests\n stream.close(NGHTTP2_REFUSED_STREAM);\n return;\n }\n const auth = new URL(`tcp://${headers[':authority']}`);\n // It's a very good idea to verify that hostname and port are\n // things this proxy should be connecting to.\n const socket = net.connect(auth.port, auth.hostname, () => {\n stream.respond();\n socket.pipe(stream);\n stream.pipe(socket);\n });\n socket.on('error', (error) => {\n stream.close(http2.constants.NGHTTP2_CONNECT_ERROR);\n });\n});\n\nproxy.listen(8001);\n</code></pre>\n<p>An HTTP/2 CONNECT client:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\n\nconst client = http2.connect('http://localhost:8001');\n\n// Must not specify the ':path' and ':scheme' headers\n// for CONNECT requests or an error will be thrown.\nconst req = client.request({\n ':method': 'CONNECT',\n ':authority': `localhost:${port}`\n});\n\nreq.on('response', (headers) => {\n console.log(headers[http2.constants.HTTP2_HEADER_STATUS]);\n});\nlet data = '';\nreq.setEncoding('utf8');\nreq.on('data', (chunk) => data += chunk);\nreq.on('end', () => {\n console.log(`The server says: ${data}`);\n client.close();\n});\nreq.end('Jane');\n</code></pre>",
"type": "module",
"displayName": "Supporting the CONNECT method"
},
{
"textRaw": "The Extended CONNECT Protocol",
"name": "the_extended_connect_protocol",
"desc": "<p><a href=\"https://tools.ietf.org/html/rfc8441\">RFC 8441</a> defines an \"Extended CONNECT Protocol\" extension to HTTP/2 that\nmay be used to bootstrap the use of an <code>Http2Stream</code> using the <code>CONNECT</code>\nmethod as a tunnel for other communication protocols (such as WebSockets).</p>\n<p>The use of the Extended CONNECT Protocol is enabled by HTTP/2 servers by using\nthe <code>enableConnectProtocol</code> setting:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst settings = { enableConnectProtocol: true };\nconst server = http2.createServer({ settings });\n</code></pre>\n<p>Once the client receives the <code>SETTINGS</code> frame from the server indicating that\nthe extended CONNECT may be used, it may send <code>CONNECT</code> requests that use the\n<code>':protocol'</code> HTTP/2 pseudo-header:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst client = http2.connect('http://localhost:8080');\nclient.on('remoteSettings', (settings) => {\n if (settings.enableConnectProtocol) {\n const req = client.request({ ':method': 'CONNECT', ':protocol': 'foo' });\n // ...\n }\n});\n</code></pre>",
"type": "module",
"displayName": "The Extended CONNECT Protocol"
}
],
"classes": [
{
"textRaw": "Class: Http2Session",
"type": "class",
"name": "Http2Session",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<ul>\n<li>Extends: <a href=\"events.html#events_class_eventemitter\" class=\"type\"><EventEmitter></a></li>\n</ul>\n<p>Instances of the <code>http2.Http2Session</code> class represent an active communications\nsession between an HTTP/2 client and server. Instances of this class are <em>not</em>\nintended to be constructed directly by user code.</p>\n<p>Each <code>Http2Session</code> instance will exhibit slightly different behaviors\ndepending on whether it is operating as a server or a client. The\n<code>http2session.type</code> property can be used to determine the mode in which an\n<code>Http2Session</code> is operating. On the server side, user code should rarely\nhave occasion to work with the <code>Http2Session</code> object directly, with most\nactions typically taken through interactions with either the <code>Http2Server</code> or\n<code>Http2Stream</code> objects.</p>\n<p>User code will not create <code>Http2Session</code> instances directly. Server-side\n<code>Http2Session</code> instances are created by the <code>Http2Server</code> instance when a\nnew HTTP/2 connection is received. Client-side <code>Http2Session</code> instances are\ncreated using the <code>http2.connect()</code> method.</p>",
"modules": [
{
"textRaw": "Http2Session and Sockets",
"name": "http2session_and_sockets",
"desc": "<p>Every <code>Http2Session</code> instance is associated with exactly one <a href=\"net.html#net_class_net_socket\"><code>net.Socket</code></a> or\n<a href=\"tls.html#tls_class_tls_tlssocket\"><code>tls.TLSSocket</code></a> when it is created. When either the <code>Socket</code> or the\n<code>Http2Session</code> are destroyed, both will be destroyed.</p>\n<p>Because the of the specific serialization and processing requirements imposed\nby the HTTP/2 protocol, it is not recommended for user code to read data from\nor write data to a <code>Socket</code> instance bound to a <code>Http2Session</code>. Doing so can\nput the HTTP/2 session into an indeterminate state causing the session and\nthe socket to become unusable.</p>\n<p>Once a <code>Socket</code> has been bound to an <code>Http2Session</code>, user code should rely\nsolely on the API of the <code>Http2Session</code>.</p>",
"type": "module",
"displayName": "Http2Session and Sockets"
}
],
"events": [
{
"textRaw": "Event: 'close'",
"type": "event",
"name": "close",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [],
"desc": "<p>The <code>'close'</code> event is emitted once the <code>Http2Session</code> has been destroyed. Its\nlistener does not expect any arguments.</p>"
},
{
"textRaw": "Event: 'connect'",
"type": "event",
"name": "connect",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`session` {Http2Session}",
"name": "session",
"type": "Http2Session"
},
{
"textRaw": "`socket` {net.Socket}",
"name": "socket",
"type": "net.Socket"
}
],
"desc": "<p>The <code>'connect'</code> event is emitted once the <code>Http2Session</code> has been successfully\nconnected to the remote peer and communication may begin.</p>\n<p>User code will typically not listen for this event directly.</p>"
},
{
"textRaw": "Event: 'error'",
"type": "event",
"name": "error",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`error` {Error}",
"name": "error",
"type": "Error"
}
],
"desc": "<p>The <code>'error'</code> event is emitted when an error occurs during the processing of\nan <code>Http2Session</code>.</p>"
},
{
"textRaw": "Event: 'frameError'",
"type": "event",
"name": "frameError",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`type` {integer} The frame type.",
"name": "type",
"type": "integer",
"desc": "The frame type."
},
{
"textRaw": "`code` {integer} The error code.",
"name": "code",
"type": "integer",
"desc": "The error code."
},
{
"textRaw": "`id` {integer} The stream id (or `0` if the frame isn't associated with a stream).",
"name": "id",
"type": "integer",
"desc": "The stream id (or `0` if the frame isn't associated with a stream)."
}
],
"desc": "<p>The <code>'frameError'</code> event is emitted when an error occurs while attempting to\nsend a frame on the session. If the frame that could not be sent is associated\nwith a specific <code>Http2Stream</code>, an attempt to emit <code>'frameError'</code> event on the\n<code>Http2Stream</code> is made.</p>\n<p>If the <code>'frameError'</code> event is associated with a stream, the stream will be\nclosed and destroyed immediately following the <code>'frameError'</code> event. If the\nevent is not associated with a stream, the <code>Http2Session</code> will be shut down\nimmediately following the <code>'frameError'</code> event.</p>"
},
{
"textRaw": "Event: 'goaway'",
"type": "event",
"name": "goaway",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`errorCode` {number} The HTTP/2 error code specified in the `GOAWAY` frame.",
"name": "errorCode",
"type": "number",
"desc": "The HTTP/2 error code specified in the `GOAWAY` frame."
},
{
"textRaw": "`lastStreamID` {number} The ID of the last stream the remote peer successfully processed (or `0` if no ID is specified).",
"name": "lastStreamID",
"type": "number",
"desc": "The ID of the last stream the remote peer successfully processed (or `0` if no ID is specified)."
},
{
"textRaw": "`opaqueData` {Buffer} If additional opaque data was included in the `GOAWAY` frame, a `Buffer` instance will be passed containing that data.",
"name": "opaqueData",
"type": "Buffer",
"desc": "If additional opaque data was included in the `GOAWAY` frame, a `Buffer` instance will be passed containing that data."
}
],
"desc": "<p>The <code>'goaway'</code> event is emitted when a <code>GOAWAY</code> frame is received.</p>\n<p>The <code>Http2Session</code> instance will be shut down automatically when the <code>'goaway'</code>\nevent is emitted.</p>"
},
{
"textRaw": "Event: 'localSettings'",
"type": "event",
"name": "localSettings",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`settings` {HTTP/2 Settings Object} A copy of the `SETTINGS` frame received.",
"name": "settings",
"type": "HTTP/2 Settings Object",
"desc": "A copy of the `SETTINGS` frame received."
}
],
"desc": "<p>The <code>'localSettings'</code> event is emitted when an acknowledgment <code>SETTINGS</code> frame\nhas been received.</p>\n<p>When using <code>http2session.settings()</code> to submit new settings, the modified\nsettings do not take effect until the <code>'localSettings'</code> event is emitted.</p>\n<pre><code class=\"language-js\">session.settings({ enablePush: false });\n\nsession.on('localSettings', (settings) => {\n /* Use the new settings */\n});\n</code></pre>"
},
{
"textRaw": "Event: 'ping'",
"type": "event",
"name": "ping",
"meta": {
"added": [
"v10.12.0"
],
"changes": []
},
"params": [
{
"textRaw": "`payload` {Buffer} The `PING` frame 8-byte payload",
"name": "payload",
"type": "Buffer",
"desc": "The `PING` frame 8-byte payload"
}
],
"desc": "<p>The <code>'ping'</code> event is emitted whenever a <code>PING</code> frame is received from the\nconnected peer.</p>"
},
{
"textRaw": "Event: 'remoteSettings'",
"type": "event",
"name": "remoteSettings",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`settings` {HTTP/2 Settings Object} A copy of the `SETTINGS` frame received.",
"name": "settings",
"type": "HTTP/2 Settings Object",
"desc": "A copy of the `SETTINGS` frame received."
}
],
"desc": "<p>The <code>'remoteSettings'</code> event is emitted when a new <code>SETTINGS</code> frame is received\nfrom the connected peer.</p>\n<pre><code class=\"language-js\">session.on('remoteSettings', (settings) => {\n /* Use the new settings */\n});\n</code></pre>"
},
{
"textRaw": "Event: 'stream'",
"type": "event",
"name": "stream",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`stream` {Http2Stream} A reference to the stream",
"name": "stream",
"type": "Http2Stream",
"desc": "A reference to the stream"
},
{
"textRaw": "`headers` {HTTP/2 Headers Object} An object describing the headers",
"name": "headers",
"type": "HTTP/2 Headers Object",
"desc": "An object describing the headers"
},
{
"textRaw": "`flags` {number} The associated numeric flags",
"name": "flags",
"type": "number",
"desc": "The associated numeric flags"
},
{
"textRaw": "`rawHeaders` {Array} An array containing the raw header names followed by their respective values.",
"name": "rawHeaders",
"type": "Array",
"desc": "An array containing the raw header names followed by their respective values."
}
],
"desc": "<p>The <code>'stream'</code> event is emitted when a new <code>Http2Stream</code> is created.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nsession.on('stream', (stream, headers, flags) => {\n const method = headers[':method'];\n const path = headers[':path'];\n // ...\n stream.respond({\n ':status': 200,\n 'content-type': 'text/plain'\n });\n stream.write('hello ');\n stream.end('world');\n});\n</code></pre>\n<p>On the server side, user code will typically not listen for this event directly,\nand would instead register a handler for the <code>'stream'</code> event emitted by the\n<code>net.Server</code> or <code>tls.Server</code> instances returned by <code>http2.createServer()</code> and\n<code>http2.createSecureServer()</code>, respectively, as in the example below:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\n\n// Create an unencrypted HTTP/2 server\nconst server = http2.createServer();\n\nserver.on('stream', (stream, headers) => {\n stream.respond({\n 'content-type': 'text/html',\n ':status': 200\n });\n stream.on('error', (error) => console.error(error));\n stream.end('<h1>Hello World</h1>');\n});\n\nserver.listen(80);\n</code></pre>\n<p>Even though HTTP/2 streams and network sockets are not in a 1:1 correspondence,\na network error will destroy each individual stream and must be handled on the\nstream level, as shown above.</p>"
},
{
"textRaw": "Event: 'timeout'",
"type": "event",
"name": "timeout",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [],
"desc": "<p>After the <code>http2session.setTimeout()</code> method is used to set the timeout period\nfor this <code>Http2Session</code>, the <code>'timeout'</code> event is emitted if there is no\nactivity on the <code>Http2Session</code> after the configured number of milliseconds.</p>\n<pre><code class=\"language-js\">session.setTimeout(2000);\nsession.on('timeout', () => { /* .. */ });\n</code></pre>"
}
],
"properties": [
{
"textRaw": "`alpnProtocol` {string|undefined}",
"type": "string|undefined",
"name": "alpnProtocol",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"desc": "<p>Value will be <code>undefined</code> if the <code>Http2Session</code> is not yet connected to a\nsocket, <code>h2c</code> if the <code>Http2Session</code> is not connected to a <code>TLSSocket</code>, or\nwill return the value of the connected <code>TLSSocket</code>'s own <code>alpnProtocol</code>\nproperty.</p>"
},
{
"textRaw": "`closed` {boolean}",
"type": "boolean",
"name": "closed",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"desc": "<p>Will be <code>true</code> if this <code>Http2Session</code> instance has been closed, otherwise\n<code>false</code>.</p>"
},
{
"textRaw": "`connecting` {boolean}",
"type": "boolean",
"name": "connecting",
"meta": {
"added": [
"v10.0.0"
],
"changes": []
},
"desc": "<p>Will be <code>true</code> if this <code>Http2Session</code> instance is still connecting, will be set\nto <code>false</code> before emitting <code>connect</code> event and/or calling the <code>http2.connect</code>\ncallback.</p>"
},
{
"textRaw": "`destroyed` {boolean}",
"type": "boolean",
"name": "destroyed",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<p>Will be <code>true</code> if this <code>Http2Session</code> instance has been destroyed and must no\nlonger be used, otherwise <code>false</code>.</p>"
},
{
"textRaw": "`encrypted` {boolean|undefined}",
"type": "boolean|undefined",
"name": "encrypted",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"desc": "<p>Value is <code>undefined</code> if the <code>Http2Session</code> session socket has not yet been\nconnected, <code>true</code> if the <code>Http2Session</code> is connected with a <code>TLSSocket</code>,\nand <code>false</code> if the <code>Http2Session</code> is connected to any other kind of socket\nor stream.</p>"
},
{
"textRaw": "`localSettings` {HTTP/2 Settings Object}",
"type": "HTTP/2 Settings Object",
"name": "localSettings",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<p>A prototype-less object describing the current local settings of this\n<code>Http2Session</code>. The local settings are local to <em>this</em> <code>Http2Session</code> instance.</p>"
},
{
"textRaw": "`originSet` {string[]|undefined}",
"type": "string[]|undefined",
"name": "originSet",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"desc": "<p>If the <code>Http2Session</code> is connected to a <code>TLSSocket</code>, the <code>originSet</code> property\nwill return an <code>Array</code> of origins for which the <code>Http2Session</code> may be\nconsidered authoritative.</p>\n<p>The <code>originSet</code> property is only available when using a secure TLS connection.</p>"
},
{
"textRaw": "`pendingSettingsAck` {boolean}",
"type": "boolean",
"name": "pendingSettingsAck",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<p>Indicates whether or not the <code>Http2Session</code> is currently waiting for an\nacknowledgment for a sent <code>SETTINGS</code> frame. Will be <code>true</code> after calling the\n<code>http2session.settings()</code> method. Will be <code>false</code> once all sent SETTINGS\nframes have been acknowledged.</p>"
},
{
"textRaw": "`remoteSettings` {HTTP/2 Settings Object}",
"type": "HTTP/2 Settings Object",
"name": "remoteSettings",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<p>A prototype-less object describing the current remote settings of this\n<code>Http2Session</code>. The remote settings are set by the <em>connected</em> HTTP/2 peer.</p>"
},
{
"textRaw": "`socket` {net.Socket|tls.TLSSocket}",
"type": "net.Socket|tls.TLSSocket",
"name": "socket",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<p>Returns a <code>Proxy</code> object that acts as a <code>net.Socket</code> (or <code>tls.TLSSocket</code>) but\nlimits available methods to ones safe to use with HTTP/2.</p>\n<p><code>destroy</code>, <code>emit</code>, <code>end</code>, <code>pause</code>, <code>read</code>, <code>resume</code>, and <code>write</code> will throw\nan error with code <code>ERR_HTTP2_NO_SOCKET_MANIPULATION</code>. See\n<a href=\"#http2_http2session_and_sockets\"><code>Http2Session</code> and Sockets</a> for more information.</p>\n<p><code>setTimeout</code> method will be called on this <code>Http2Session</code>.</p>\n<p>All other interactions will be routed directly to the socket.</p>"
},
{
"textRaw": "http2session.state",
"name": "state",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<p>Provides miscellaneous information about the current state of the\n<code>Http2Session</code>.</p>\n<ul>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a></p>\n<ul>\n<li><code>effectiveLocalWindowSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The current local (receive)\nflow control window size for the <code>Http2Session</code>.</li>\n<li><code>effectiveRecvDataLength</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The current number of bytes\nthat have been received since the last flow control <code>WINDOW_UPDATE</code>.</li>\n<li><code>nextStreamID</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The numeric identifier to be used the\nnext time a new <code>Http2Stream</code> is created by this <code>Http2Session</code>.</li>\n<li><code>localWindowSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The number of bytes that the remote peer can\nsend without receiving a <code>WINDOW_UPDATE</code>.</li>\n<li><code>lastProcStreamID</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The numeric id of the <code>Http2Stream</code>\nfor which a <code>HEADERS</code> or <code>DATA</code> frame was most recently received.</li>\n<li><code>remoteWindowSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The number of bytes that this <code>Http2Session</code>\nmay send without receiving a <code>WINDOW_UPDATE</code>.</li>\n<li><code>outboundQueueSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The number of frames currently within the\noutbound queue for this <code>Http2Session</code>.</li>\n<li><code>deflateDynamicTableSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The current size in bytes of the\noutbound header compression state table.</li>\n<li><code>inflateDynamicTableSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The current size in bytes of the\ninbound header compression state table.</li>\n</ul>\n</li>\n</ul>\n<p>An object describing the current status of this <code>Http2Session</code>.</p>"
},
{
"textRaw": "`type` {number}",
"type": "number",
"name": "type",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<p>The <code>http2session.type</code> will be equal to\n<code>http2.constants.NGHTTP2_SESSION_SERVER</code> if this <code>Http2Session</code> instance is a\nserver, and <code>http2.constants.NGHTTP2_SESSION_CLIENT</code> if the instance is a\nclient.</p>"
}
],
"methods": [
{
"textRaw": "http2session.close([callback])",
"type": "method",
"name": "close",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"optional": true
}
]
}
],
"desc": "<p>Gracefully closes the <code>Http2Session</code>, allowing any existing streams to\ncomplete on their own and preventing new <code>Http2Stream</code> instances from being\ncreated. Once closed, <code>http2session.destroy()</code> <em>might</em> be called if there\nare no open <code>Http2Stream</code> instances.</p>\n<p>If specified, the <code>callback</code> function is registered as a handler for the\n<code>'close'</code> event.</p>"
},
{
"textRaw": "http2session.destroy([error][, code])",
"type": "method",
"name": "destroy",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`error` {Error} An `Error` object if the `Http2Session` is being destroyed due to an error.",
"name": "error",
"type": "Error",
"desc": "An `Error` object if the `Http2Session` is being destroyed due to an error.",
"optional": true
},
{
"textRaw": "`code` {number} The HTTP/2 error code to send in the final `GOAWAY` frame. If unspecified, and `error` is not undefined, the default is `INTERNAL_ERROR`, otherwise defaults to `NO_ERROR`.",
"name": "code",
"type": "number",
"desc": "The HTTP/2 error code to send in the final `GOAWAY` frame. If unspecified, and `error` is not undefined, the default is `INTERNAL_ERROR`, otherwise defaults to `NO_ERROR`.",
"optional": true
}
]
}
],
"desc": "<p>Immediately terminates the <code>Http2Session</code> and the associated <code>net.Socket</code> or\n<code>tls.TLSSocket</code>.</p>\n<p>Once destroyed, the <code>Http2Session</code> will emit the <code>'close'</code> event. If <code>error</code>\nis not undefined, an <code>'error'</code> event will be emitted immediately before the\n<code>'close'</code> event.</p>\n<p>If there are any remaining open <code>Http2Streams</code> associated with the\n<code>Http2Session</code>, those will also be destroyed.</p>"
},
{
"textRaw": "http2session.goaway([code[, lastStreamID[, opaqueData]]])",
"type": "method",
"name": "goaway",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`code` {number} An HTTP/2 error code",
"name": "code",
"type": "number",
"desc": "An HTTP/2 error code",
"optional": true
},
{
"textRaw": "`lastStreamID` {number} The numeric ID of the last processed `Http2Stream`",
"name": "lastStreamID",
"type": "number",
"desc": "The numeric ID of the last processed `Http2Stream`",
"optional": true
},
{
"textRaw": "`opaqueData` {Buffer|TypedArray|DataView} A `TypedArray` or `DataView` instance containing additional data to be carried within the `GOAWAY` frame.",
"name": "opaqueData",
"type": "Buffer|TypedArray|DataView",
"desc": "A `TypedArray` or `DataView` instance containing additional data to be carried within the `GOAWAY` frame.",
"optional": true
}
]
}
],
"desc": "<p>Transmits a <code>GOAWAY</code> frame to the connected peer <em>without</em> shutting down the\n<code>Http2Session</code>.</p>"
},
{
"textRaw": "http2session.ping([payload, ]callback)",
"type": "method",
"name": "ping",
"meta": {
"added": [
"v8.9.3"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {boolean}",
"name": "return",
"type": "boolean"
},
"params": [
{
"textRaw": "`payload` {Buffer|TypedArray|DataView} Optional ping payload.",
"name": "payload",
"type": "Buffer|TypedArray|DataView",
"desc": "Optional ping payload.",
"optional": true
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function"
}
]
}
],
"desc": "<p>Sends a <code>PING</code> frame to the connected HTTP/2 peer. A <code>callback</code> function must\nbe provided. The method will return <code>true</code> if the <code>PING</code> was sent, <code>false</code>\notherwise.</p>\n<p>The maximum number of outstanding (unacknowledged) pings is determined by the\n<code>maxOutstandingPings</code> configuration option. The default maximum is 10.</p>\n<p>If provided, the <code>payload</code> must be a <code>Buffer</code>, <code>TypedArray</code>, or <code>DataView</code>\ncontaining 8 bytes of data that will be transmitted with the <code>PING</code> and\nreturned with the ping acknowledgment.</p>\n<p>The callback will be invoked with three arguments: an error argument that will\nbe <code>null</code> if the <code>PING</code> was successfully acknowledged, a <code>duration</code> argument\nthat reports the number of milliseconds elapsed since the ping was sent and the\nacknowledgment was received, and a <code>Buffer</code> containing the 8-byte <code>PING</code>\npayload.</p>\n<pre><code class=\"language-js\">session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {\n if (!err) {\n console.log(`Ping acknowledged in ${duration} milliseconds`);\n console.log(`With payload '${payload.toString()}'`);\n }\n});\n</code></pre>\n<p>If the <code>payload</code> argument is not specified, the default payload will be the\n64-bit timestamp (little endian) marking the start of the <code>PING</code> duration.</p>"
},
{
"textRaw": "http2session.ref()",
"type": "method",
"name": "ref",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"signatures": [
{
"params": []
}
],
"desc": "<p>Calls <a href=\"net.html#net_socket_ref\"><code>ref()</code></a> on this <code>Http2Session</code>\ninstance's underlying <a href=\"net.html#net_class_net_socket\"><code>net.Socket</code></a>.</p>"
},
{
"textRaw": "http2session.setTimeout(msecs, callback)",
"type": "method",
"name": "setTimeout",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`msecs` {number}",
"name": "msecs",
"type": "number"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function"
}
]
}
],
"desc": "<p>Used to set a callback function that is called when there is no activity on\nthe <code>Http2Session</code> after <code>msecs</code> milliseconds. The given <code>callback</code> is\nregistered as a listener on the <code>'timeout'</code> event.</p>"
},
{
"textRaw": "http2session.settings(settings)",
"type": "method",
"name": "settings",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`settings` {HTTP/2 Settings Object}",
"name": "settings",
"type": "HTTP/2 Settings Object"
}
]
}
],
"desc": "<p>Updates the current local settings for this <code>Http2Session</code> and sends a new\n<code>SETTINGS</code> frame to the connected HTTP/2 peer.</p>\n<p>Once called, the <code>http2session.pendingSettingsAck</code> property will be <code>true</code>\nwhile the session is waiting for the remote peer to acknowledge the new\nsettings.</p>\n<p>The new settings will not become effective until the <code>SETTINGS</code> acknowledgment\nis received and the <code>'localSettings'</code> event is emitted. It is possible to send\nmultiple <code>SETTINGS</code> frames while acknowledgment is still pending.</p>"
},
{
"textRaw": "http2session.unref()",
"type": "method",
"name": "unref",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"signatures": [
{
"params": []
}
],
"desc": "<p>Calls <a href=\"net.html#net_socket_unref\"><code>unref()</code></a> on this <code>Http2Session</code>\ninstance's underlying <a href=\"net.html#net_class_net_socket\"><code>net.Socket</code></a>.</p>"
}
]
},
{
"textRaw": "Class: ServerHttp2Session",
"type": "class",
"name": "ServerHttp2Session",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"methods": [
{
"textRaw": "serverhttp2session.altsvc(alt, originOrStream)",
"type": "method",
"name": "altsvc",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`alt` {string} A description of the alternative service configuration as defined by [RFC 7838][].",
"name": "alt",
"type": "string",
"desc": "A description of the alternative service configuration as defined by [RFC 7838][]."
},
{
"textRaw": "`originOrStream` {number|string|URL|Object} Either a URL string specifying the origin (or an `Object` with an `origin` property) or the numeric identifier of an active `Http2Stream` as given by the `http2stream.id` property.",
"name": "originOrStream",
"type": "number|string|URL|Object",
"desc": "Either a URL string specifying the origin (or an `Object` with an `origin` property) or the numeric identifier of an active `Http2Stream` as given by the `http2stream.id` property."
}
]
}
],
"desc": "<p>Submits an <code>ALTSVC</code> frame (as defined by <a href=\"https://tools.ietf.org/html/rfc7838\">RFC 7838</a>) to the connected client.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\n\nconst server = http2.createServer();\nserver.on('session', (session) => {\n // Set altsvc for origin https://example.org:80\n session.altsvc('h2=\":8000\"', 'https://example.org:80');\n});\n\nserver.on('stream', (stream) => {\n // Set altsvc for a specific stream\n stream.session.altsvc('h2=\":8000\"', stream.id);\n});\n</code></pre>\n<p>Sending an <code>ALTSVC</code> frame with a specific stream ID indicates that the alternate\nservice is associated with the origin of the given <code>Http2Stream</code>.</p>\n<p>The <code>alt</code> and origin string <em>must</em> contain only ASCII bytes and are\nstrictly interpreted as a sequence of ASCII bytes. The special value <code>'clear'</code>\nmay be passed to clear any previously set alternative service for a given\ndomain.</p>\n<p>When a string is passed for the <code>originOrStream</code> argument, it will be parsed as\na URL and the origin will be derived. For instance, the origin for the\nHTTP URL <code>'https://example.org/foo/bar'</code> is the ASCII string\n<code>'https://example.org'</code>. An error will be thrown if either the given string\ncannot be parsed as a URL or if a valid origin cannot be derived.</p>\n<p>A <code>URL</code> object, or any object with an <code>origin</code> property, may be passed as\n<code>originOrStream</code>, in which case the value of the <code>origin</code> property will be\nused. The value of the <code>origin</code> property <em>must</em> be a properly serialized\nASCII origin.</p>"
},
{
"textRaw": "serverhttp2session.origin(...origins)",
"type": "method",
"name": "origin",
"meta": {
"added": [
"v10.12.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"name": "...origins"
}
]
}
],
"desc": "<p>Submits an <code>ORIGIN</code> frame (as defined by <a href=\"https://tools.ietf.org/html/rfc8336\">RFC 8336</a>) to the connected client\nto advertise the set of origins for which the server is capable of providing\nauthoritative responses.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst options = getSecureOptionsSomehow();\nconst server = http2.createSecureServer(options);\nserver.on('stream', (stream) => {\n stream.respond();\n stream.end('ok');\n});\nserver.on('session', (session) => {\n session.origin('https://example.com', 'https://example.org');\n});\n</code></pre>\n<p>When a string is passed as an <code>origin</code>, it will be parsed as a URL and the\norigin will be derived. For instance, the origin for the HTTP URL\n<code>'https://example.org/foo/bar'</code> is the ASCII string\n<code>'https://example.org'</code>. An error will be thrown if either the given string\ncannot be parsed as a URL or if a valid origin cannot be derived.</p>\n<p>A <code>URL</code> object, or any object with an <code>origin</code> property, may be passed as\nan <code>origin</code>, in which case the value of the <code>origin</code> property will be\nused. The value of the <code>origin</code> property <em>must</em> be a properly serialized\nASCII origin.</p>\n<p>Alternatively, the <code>origins</code> option may be used when creating a new HTTP/2\nserver using the <code>http2.createSecureServer()</code> method:</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst options = getSecureOptionsSomehow();\noptions.origins = ['https://example.com', 'https://example.org'];\nconst server = http2.createSecureServer(options);\nserver.on('stream', (stream) => {\n stream.respond();\n stream.end('ok');\n});\n</code></pre>"
}
],
"modules": [
{
"textRaw": "Specifying alternative services",
"name": "specifying_alternative_services",
"desc": "<p>The format of the <code>alt</code> parameter is strictly defined by <a href=\"https://tools.ietf.org/html/rfc7838\">RFC 7838</a> as an\nASCII string containing a comma-delimited list of \"alternative\" protocols\nassociated with a specific host and port.</p>\n<p>For example, the value <code>'h2=\"example.org:81\"'</code> indicates that the HTTP/2\nprotocol is available on the host <code>'example.org'</code> on TCP/IP port 81. The\nhost and port <em>must</em> be contained within the quote (<code>\"</code>) characters.</p>\n<p>Multiple alternatives may be specified, for instance: <code>'h2=\"example.org:81\", h2=\":82\"'</code>.</p>\n<p>The protocol identifier (<code>'h2'</code> in the examples) may be any valid\n<a href=\"https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids\">ALPN Protocol ID</a>.</p>\n<p>The syntax of these values is not validated by the Node.js implementation and\nare passed through as provided by the user or received from the peer.</p>",
"type": "module",
"displayName": "Specifying alternative services"
}
]
},
{
"textRaw": "Class: ClientHttp2Session",
"type": "class",
"name": "ClientHttp2Session",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"events": [
{
"textRaw": "Event: 'altsvc'",
"type": "event",
"name": "altsvc",
"meta": {
"added": [
"v9.4.0"
],
"changes": []
},
"params": [
{
"textRaw": "`alt` {string}",
"name": "alt",
"type": "string"
},
{
"textRaw": "`origin` {string}",
"name": "origin",
"type": "string"
},
{
"textRaw": "`streamId` {number}",
"name": "streamId",
"type": "number"
}
],
"desc": "<p>The <code>'altsvc'</code> event is emitted whenever an <code>ALTSVC</code> frame is received by\nthe client. The event is emitted with the <code>ALTSVC</code> value, origin, and stream\nID. If no <code>origin</code> is provided in the <code>ALTSVC</code> frame, <code>origin</code> will\nbe an empty string.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst client = http2.connect('https://example.org');\n\nclient.on('altsvc', (alt, origin, streamId) => {\n console.log(alt);\n console.log(origin);\n console.log(streamId);\n});\n</code></pre>"
},
{
"textRaw": "Event: 'origin'",
"type": "event",
"name": "origin",
"meta": {
"added": [
"v10.12.0"
],
"changes": []
},
"params": [
{
"textRaw": "`origins` {string[]}",
"name": "origins",
"type": "string[]"
}
],
"desc": "<p>The <code>'origin'</code> event is emitted whenever an <code>ORIGIN</code> frame is received by\nthe client. The event is emitted with an array of <code>origin</code> strings. The\n<code>http2session.originSet</code> will be updated to include the received\norigins.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst client = http2.connect('https://example.org');\n\nclient.on('origin', (origins) => {\n for (let n = 0; n < origins.length; n++)\n console.log(origins[n]);\n});\n</code></pre>\n<p>The <code>'origin'</code> event is only emitted when using a secure TLS connection.</p>"
}
],
"methods": [
{
"textRaw": "clienthttp2session.request(headers[, options])",
"type": "method",
"name": "request",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {ClientHttp2Stream}",
"name": "return",
"type": "ClientHttp2Stream"
},
"params": [
{
"textRaw": "`headers` {HTTP/2 Headers Object}",
"name": "headers",
"type": "HTTP/2 Headers Object"
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`endStream` {boolean} `true` if the `Http2Stream` *writable* side should be closed initially, such as when sending a `GET` request that should not expect a payload body.",
"name": "endStream",
"type": "boolean",
"desc": "`true` if the `Http2Stream` *writable* side should be closed initially, such as when sending a `GET` request that should not expect a payload body."
},
{
"textRaw": "`exclusive` {boolean} When `true` and `parent` identifies a parent Stream, the created stream is made the sole direct dependency of the parent, with all other existing dependents made a dependent of the newly created stream. **Default:** `false`.",
"name": "exclusive",
"type": "boolean",
"default": "`false`",
"desc": "When `true` and `parent` identifies a parent Stream, the created stream is made the sole direct dependency of the parent, with all other existing dependents made a dependent of the newly created stream."
},
{
"textRaw": "`parent` {number} Specifies the numeric identifier of a stream the newly created stream is dependent on.",
"name": "parent",
"type": "number",
"desc": "Specifies the numeric identifier of a stream the newly created stream is dependent on."
},
{
"textRaw": "`weight` {number} Specifies the relative dependency of a stream in relation to other streams with the same `parent`. The value is a number between `1` and `256` (inclusive).",
"name": "weight",
"type": "number",
"desc": "Specifies the relative dependency of a stream in relation to other streams with the same `parent`. The value is a number between `1` and `256` (inclusive)."
},
{
"textRaw": "`waitForTrailers` {boolean} When `true`, the `Http2Stream` will emit the `'wantTrailers'` event after the final `DATA` frame has been sent.",
"name": "waitForTrailers",
"type": "boolean",
"desc": "When `true`, the `Http2Stream` will emit the `'wantTrailers'` event after the final `DATA` frame has been sent."
}
],
"optional": true
}
]
}
],
"desc": "<p>For HTTP/2 Client <code>Http2Session</code> instances only, the <code>http2session.request()</code>\ncreates and returns an <code>Http2Stream</code> instance that can be used to send an\nHTTP/2 request to the connected server.</p>\n<p>This method is only available if <code>http2session.type</code> is equal to\n<code>http2.constants.NGHTTP2_SESSION_CLIENT</code>.</p>\n<pre><code class=\"language-js\">const http2 = require('http2');\nconst clientSession = http2.connect('https://localhost:1234');\nconst {\n HTTP2_HEADER_PATH,\n HTTP2_HEADER_STATUS\n} = http2.constants;\n\nconst req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });\nreq.on('response', (headers) => {\n console.log(headers[HTTP2_HEADER_STATUS]);\n req.on('data', (chunk) => { /* .. */ });\n req.on('end', () => { /* .. */ });\n});\n</code></pre>\n<p>When the <code>options.waitForTrailers</code> option is set, the <code>'wantTrailers'</code> event\nis emitted immediately after queuing the last chunk of payload data to be sent.\nThe <code>http2stream.sendTrailers()</code> method can then be called to send trailing\nheaders to the peer.</p>\n<p>When <code>options.waitForTrailers</code> is set, the <code>Http2Stream</code> will not automatically\nclose when the final <code>DATA</code> frame is transmitted. User code must call either\n<code>http2stream.sendTrailers()</code> or <code>http2stream.close()</code> to close the\n<code>Http2Stream</code>.</p>\n<p>The <code>:method</code> and <code>:path</code> pseudo-headers are not specified within <code>headers</code>,\nthey respectively default to:</p>\n<ul>\n<li><code>:method</code> = <code>'GET'</code></li>\n<li><code>:path</code> = <code>/</code></li>\n</ul>"
}
]
},
{
"textRaw": "Class: Http2Stream",
"type": "class",
"name": "Http2Stream",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"desc": "<ul>\n<li>Extends: <a href=\"stream.html#stream_class_stream_duplex\" class=\"type\"><stream.Duplex></a></li>\n</ul>\n<p>Each instance of the <code>Http2Stream</code> class represents a bidirectional HTTP/2\ncommunications stream over an <code>Http2Session</code> instance. Any single <code>Http2Session</code>\nmay have up to 2<sup>31</sup>-1 <code>Http2Stream</code> instances over its lifetime.</p>\n<p>User code will not construct <code>Http2Stream</code> instances directly. Rather, these\nare created, managed, and provided to user code through the <code>Http2Session</code>\ninstance. On the server, <code>Http2Stream</code> instances are created either in response\nto an incoming HTTP request (and handed off to user code via the <code>'stream'</code>\nevent), or in response to a call to the <code>http2stream.pushStream()</code> method.\nOn the client, <code>Http2Stream</code> instances are created and returned when either the\n<code>http2session.request()</code> method is called, or in response to an incoming\n<code>'push'</code> event.</p>\n<p>The <code>Http2Stream</code> class is a base for the <a href=\"#http2_class_serverhttp2stream\"><code>ServerHttp2Stream</code></a> and\n<a href=\"#http2_class_clienthttp2stream\"><code>ClientHttp2Stream</code></a> classes, each of which is used specifically by either\nthe Server or Client side, respectively.</p>\n<p>All <code>Http2Stream</code> instances are <a href=\"stream.html#stream_class_stream_duplex\"><code>Duplex</code></a> streams. The <code>Writable</code> side of the\n<code>Duplex</code> is used to send data to the connected peer, while the <code>Readable</code> side\nis used to receive data sent by the connected peer.</p>",
"modules": [
{
"textRaw": "Http2Stream Lifecycle",
"name": "http2stream_lifecycle",
"modules": [
{
"textRaw": "Creation",
"name": "creation",
"desc": "<p>On the server side, instances of <a href=\"#http2_class_serverhttp2stream\"><code>ServerHttp2Stream</code></a> are created either\nwhen:</p>\n<ul>\n<li>A new HTTP/2 <code>HEADERS</code> frame with a previously unused stream ID is received;</li>\n<li>The <code>http2stream.pushStream()</code> method is called.</li>\n</ul>\n<p>On the client side, instances of <a href=\"#http2_class_clienthttp2stream\"><code>ClientHttp2Stream</code></a> are created when the\n<code>http2session.request()</code> method is called.</p>\n<p>On the client, the <code>Http2Stream</code> instance returned by <code>http2session.request()</code>\nmay not be immediately ready for use if the parent <code>Http2Session</code> has not yet\nbeen fully established. In such cases, operations called on the <code>Http2Stream</code>\nwill be buffered until the <code>'ready'</code> event is emitted. User code should rarely,\nif ever, need to handle the <code>'ready'</code> event directly. The ready status of an\n<code>Http2Stream</code> can be determined by checking the value of <code>http2stream.id</code>. If\nthe value is <code>undefined</code>, the stream is not yet ready for use.</p>",
"type": "module",
"displayName": "Creation"
},
{
"textRaw": "Destruction",
"name": "destruction",
"desc": "<p>All <a href=\"#http2_class_http2stream\"><code>Http2Stream</code></a> instances are destroyed either when:</p>\n<ul>\n<li>An <code>RST_STREAM</code> frame for the stream is received by the connected peer.</li>\n<li>The <code>http2stream.close()</code> method is called.</li>\n<li>The <code>http2stream.destroy()</code> or <code>http2session.destroy()</code> methods are called.</li>\n</ul>\n<p>When an <code>Http2Stream</code> instance is destroyed, an attempt will be made to send an\n<code>RST_STREAM</code> frame will be sent to the connected peer.</p>\n<p>When the <code>Http2Stream</code> instance is destroyed, the <code>'close'</code> event will\nbe emitted. Because <code>Http2Stream</code> is an instance of <code>stream.Duplex</code>, the\n<code>'end'</code> event will also be emitted if the stream data is currently flowing.\nThe <code>'error'</code> event may also be emitted if <code>http2stream.destroy()</code> was called\nwith an <code>Error</code> passed as the first argument.</p>\n<p>After the <code>Http2Stream</code> has been destroyed, the <code>http2stream.destroyed</code>\nproperty will be <code>true</code> and the <code>http2stream.rstCode</code> property will specify the\n<code>RST_STREAM</code> error code. The <code>Http2Stream</code> instance is no longer usable once\ndestroyed.</p>",
"type": "module",
"displayName": "Destruction"
}
],
"type": "module",
"displayName": "Http2Stream Lifecycle"
}
],
"events": [
{
"textRaw": "Event: 'aborted'",
"type": "event",
"name": "aborted",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [],
"desc": "<p>The <code>'aborted'</code> event is emitted whenever a <code>Http2Stream</code> instance is\nabnormally aborted in mid-communication.</p>\n<p>The <code>'aborted'</code> event will only be emitted if the <code>Http2Stream</code> writable side\nhas not been ended.</p>"
},
{
"textRaw": "Event: 'close'",
"type": "event",
"name": "close",
"meta": {
"added": [
"v8.4.0"
],
"changes": []
},
"params": [],
"desc": "<p>The <code>'close'</code> event is emitted when the <code>Http2Stream</code> is destroyed. Once\nthis event is emitted, the <code>Http2Stream</code> instance is no longer usable.</p>\n<p>The HTTP/2 error code used when closing the stream can be retrieved using\nthe <code>http2stream.rstCode</code> property. If the code is any value other than\n<code>NGHTTP2_NO_ERROR</code> (<code>0</code>), an <code>'error'</code> event will have also been emitted.</p>"
},
{
"textRaw": "Event: 'error'",
"type": "event",
"name": "error",
"meta": {
"added": [