@@ -12,6 +12,7 @@ This directory contains modules used to test the Node.js implementation.
1212* [ Fixtures module] ( #fixtures-module )
1313* [ Internet module] ( #internet-module )
1414* [ WPT module] ( #wpt-module )
15+ * [ HTTP2 module] ( #http2-module )
1516
1617## Benchmark Module
1718
@@ -551,6 +552,143 @@ Node.js
551552implementation with tests from
552553[ W3C Web Platform Tests] ( https://github.com/w3c/web-platform-tests ) .
553554
555+ ## HTTP/2 Module
556+
557+ The http2.js module provides a handful of utilities for creating mock HTTP/2
558+ frames for testing of HTTP/2 endpoints
559+
560+ <!-- eslint-disable strict -->
561+ <!-- eslint-disable required-modules -->
562+ <!-- eslint-disable no-unused-vars -->
563+ <!-- eslint-disable no-undef -->
564+ ``` js
565+ const http2 = require (' ../common/http2' );
566+ ```
567+
568+ ### Class: Frame
569+
570+ The ` http2.Frame ` is a base class that creates a ` Buffer ` containing a
571+ serialized HTTP/2 frame header.
572+
573+ <!-- eslint-disable strict -->
574+ <!-- eslint-disable required-modules -->
575+ <!-- eslint-disable no-unused-vars -->
576+ <!-- eslint-disable no-undef -->
577+ ``` js
578+ // length is a 24-bit unsigned integer
579+ // type is an 8-bit unsigned integer identifying the frame type
580+ // flags is an 8-bit unsigned integer containing the flag bits
581+ // id is the 32-bit stream identifier, if any.
582+ const frame = new http2.Frame (length, type, flags, id);
583+
584+ // Write the frame data to a socket
585+ socket .write (frame .data );
586+ ```
587+
588+ The serialized ` Buffer ` may be retrieved using the ` frame.data ` property.
589+
590+ ### Class: DataFrame extends Frame
591+
592+ The ` http2.DataFrame ` is a subclass of ` http2.Frame ` that serializes a ` DATA `
593+ frame.
594+
595+ <!-- eslint-disable strict -->
596+ <!-- eslint-disable required-modules -->
597+ <!-- eslint-disable no-unused-vars -->
598+ <!-- eslint-disable no-undef -->
599+ ``` js
600+ // id is the 32-bit stream identifier
601+ // payload is a Buffer containing the DATA payload
602+ // padlen is an 8-bit integer giving the number of padding bytes to include
603+ // final is a boolean indicating whether the End-of-stream flag should be set,
604+ // defaults to false.
605+ const data = new http2.DataFrame (id, payload, padlen, final);
606+
607+ socket .write (frame .data );
608+ ```
609+
610+ ### Class: HeadersFrame
611+
612+ The ` http2.HeadersFrame ` is a subclass of ` http2.Frame ` that serializes a
613+ ` HEADERS ` frame.
614+
615+ <!-- eslint-disable strict -->
616+ <!-- eslint-disable required-modules -->
617+ <!-- eslint-disable no-unused-vars -->
618+ <!-- eslint-disable no-undef -->
619+ ``` js
620+ // id is the 32-bit stream identifier
621+ // payload is a Buffer containing the HEADERS payload (see either
622+ // http2.kFakeRequestHeaders or http2.kFakeResponseHeaders).
623+ // padlen is an 8-bit integer giving the number of padding bytes to include
624+ // final is a boolean indicating whether the End-of-stream flag should be set,
625+ // defaults to false.
626+ const data = new http2.HeadersFrame (id, http2 .kFakeRequestHeaders ,
627+ padlen, final);
628+
629+ socket .write (frame .data );
630+ ```
631+
632+ ### Class: SettingsFrame
633+
634+ The ` http2.SettingsFrame ` is a subclass of ` http2.Frame ` that serializes an
635+ empty ` SETTINGS ` frame.
636+
637+ <!-- eslint-disable strict -->
638+ <!-- eslint-disable required-modules -->
639+ <!-- eslint-disable no-unused-vars -->
640+ <!-- eslint-disable no-undef -->
641+ ``` js
642+ // ack is a boolean indicating whether or not to set the ACK flag.
643+ const frame = new http2.SettingsFrame (ack);
644+
645+ socket .write (frame .data );
646+ ```
647+
648+ ### http2.kFakeRequestHeaders
649+
650+ Set to a ` Buffer ` instance that contains a minimal set of serialized HTTP/2
651+ request headers to be used as the payload of a ` http2.HeadersFrame ` .
652+
653+ <!-- eslint-disable strict -->
654+ <!-- eslint-disable required-modules -->
655+ <!-- eslint-disable no-unused-vars -->
656+ <!-- eslint-disable no-undef -->
657+ ``` js
658+ const frame = new http2.HeadersFrame (1 , http2 .kFakeRequestHeaders , 0 , true );
659+
660+ socket .write (frame .data );
661+ ```
662+
663+ ### http2.kFakeResponseHeaders
664+
665+ Set to a ` Buffer ` instance that contains a minimal set of serialized HTTP/2
666+ response headers to be used as the payload a ` http2.HeadersFrame ` .
667+
668+ <!-- eslint-disable strict -->
669+ <!-- eslint-disable required-modules -->
670+ <!-- eslint-disable no-unused-vars -->
671+ <!-- eslint-disable no-undef -->
672+ ``` js
673+ const frame = new http2.HeadersFrame (1 , http2 .kFakeResponseHeaders , 0 , true );
674+
675+ socket .write (frame .data );
676+ ```
677+
678+ ### http2.kClientMagic
679+
680+ Set to a ` Buffer ` containing the preamble bytes an HTTP/2 client must send
681+ upon initial establishment of a connection.
682+
683+ <!-- eslint-disable strict -->
684+ <!-- eslint-disable required-modules -->
685+ <!-- eslint-disable no-unused-vars -->
686+ <!-- eslint-disable no-undef -->
687+ ``` js
688+ socket .write (http2 .kClientMagic );
689+ ```
690+
691+
554692[ < ; Array>] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
555693[ < ; ArrayBufferView[ ;] ; >] : https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView
556694[ < ; Boolean>] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
0 commit comments