Skip to content

Commit 35ee894

Browse files
jasnellMylesBorins
authored andcommitted
doc: add docs for common/http2.js utility
Backport-PR-URL: #18050 Backport-PR-URL: #20456 PR-URL: #17942 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 9a6ea7e commit 35ee894

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

test/common/README.md

+138
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This directory contains modules used to test the Node.js implementation.
1313
* [Internet module](#internet-module)
1414
* [tmpdir module](#tmpdir-module)
1515
* [WPT module](#wpt-module)
16+
* [HTTP2 module](#http2-module)
1617

1718
## Benchmark Module
1819

@@ -559,6 +560,143 @@ Node.js
559560
implementation with tests from
560561
[W3C Web Platform Tests](https://github.com/w3c/web-platform-tests).
561562

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

0 commit comments

Comments
 (0)