@@ -19,8 +19,8 @@ compatibility with the existing [HTTP/1][] module API. However,
1919the [ Compatibility API] [ ] is.
2020
2121The ` http2 ` Core API is much more symmetric between client and server than the
22- ` http ` API. For instance, most events, like ` error ` and ` socketError ` , can be
23- emitted either by client-side code or server-side code.
22+ ` http ` API. For instance, most events, like ` error ` , ` connect ` and ` stream ` , can
23+ be emitted either by client-side code or server-side code.
2424
2525### Server-side example
2626
@@ -36,7 +36,6 @@ const server = http2.createSecureServer({
3636 cert: fs .readFileSync (' localhost-cert.pem' )
3737});
3838server .on (' error' , (err ) => console .error (err));
39- server .on (' socketError' , (err ) => console .error (err));
4039
4140server .on (' stream' , (stream , headers ) => {
4241 // stream is a Duplex
@@ -68,7 +67,6 @@ const client = http2.connect('https://localhost:8443', {
6867 ca: fs .readFileSync (' localhost-cert.pem' )
6968});
7069client .on (' error' , (err ) => console .error (err));
71- client .on (' socketError' , (err ) => console .error (err));
7270
7371const req = client .request ({ ' :path' : ' /' });
7472
@@ -479,44 +477,6 @@ Used to set a callback function that is called when there is no activity on
479477the ` Http2Session ` after ` msecs ` milliseconds. The given ` callback ` is
480478registered as a listener on the ` 'timeout' ` event.
481479
482- #### http2session.close(options[ , callback] )
483- <!-- YAML
484- added: v8.4.0
485- -->
486-
487- * ` options ` {Object}
488- * ` errorCode ` {number} The HTTP/2 [ error code] [ ] to return. Note that this is
489- * not* the same thing as an HTTP Response Status Code. ** Default:** ` 0x00 `
490- (No Error).
491- * ` lastStreamID ` {number} The Stream ID of the last successfully processed
492- ` Http2Stream ` on this ` Http2Session ` . If unspecified, will default to the
493- ID of the most recently received stream.
494- * ` opaqueData ` {Buffer|Uint8Array} A ` Buffer ` or ` Uint8Array ` instance
495- containing arbitrary additional data to send to the peer upon disconnection.
496- This is used, typically, to provide additional data for debugging failures,
497- if necessary.
498- * ` callback ` {Function} A callback that is invoked after the session shutdown
499- has been completed.
500- * Returns: {undefined}
501-
502- Attempts to shut down this ` Http2Session ` using HTTP/2 defined procedures.
503- If specified, the given ` callback ` function will be invoked once the shutdown
504- process has completed.
505-
506- If the ` Http2Session ` instance is a server-side session and the ` errorCode `
507- option is ` 0x00 ` (No Error), a "graceful" shutdown will be initiated. During a
508- "graceful" shutdown, the session will first send a ` GOAWAY ` frame to
509- the connected peer identifying the last processed stream as 2<sup >31</sup >-1.
510- Then, on the next tick of the event loop, a second ` GOAWAY ` frame identifying
511- the most recently processed stream identifier is sent. This process allows the
512- remote peer to begin preparing for the connection to be terminated.
513-
514- ``` js
515- session .close ({
516- opaqueData: Buffer .from (' add some debugging data here' )
517- }, () => session .destroy ());
518- ```
519-
520480#### http2session.socket
521481<!-- YAML
522482added: v8.4.0
@@ -686,19 +646,23 @@ added: v8.4.0
686646added: v9.4.0
687647-->
688648
649+ * ` alt ` : {string}
650+ * ` origin ` : {string}
651+ * ` streamId ` : {number}
652+
689653The ` 'altsvc' ` event is emitted whenever an ` ALTSVC ` frame is received by
690654the client. The event is emitted with the ` ALTSVC ` value, origin, and stream
691- ID, if any . If no ` origin ` is provided in the ` ALTSVC ` frame, ` origin ` will
655+ ID. If no ` origin ` is provided in the ` ALTSVC ` frame, ` origin ` will
692656be an empty string.
693657
694658``` js
695659const http2 = require (' http2' );
696660const client = http2 .connect (' https://example.org' );
697661
698- client .on (' altsvc' , (alt , origin , stream ) => {
662+ client .on (' altsvc' , (alt , origin , streamId ) => {
699663 console .log (alt);
700664 console .log (origin);
701- console .log (stream );
665+ console .log (streamId );
702666});
703667```
704668
@@ -1472,10 +1436,9 @@ added: v8.4.0
14721436
14731437* Extends: {net.Server}
14741438
1475- In ` Http2Server ` , there is no ` 'clientError' ` event as there is in
1476- HTTP1. However, there are ` 'socketError' ` , ` 'sessionError' ` , and
1477- ` 'streamError' ` , for errors emitted on the socket, ` Http2Session ` , or
1478- ` Http2Stream ` .
1439+ In ` Http2Server ` , there are no ` 'clientError' ` events as there are in
1440+ HTTP1. However, there are ` 'sessionError' ` , and ` 'streamError' ` events for
1441+ errors emitted on the socket, or from ` Http2Session ` or ` Http2Stream ` instances.
14791442
14801443#### Event: 'checkContinue'
14811444<!-- YAML
@@ -1580,23 +1543,54 @@ added: v8.4.0
15801543
15811544* Extends: {tls.Server}
15821545
1583- #### Event: 'sessionError'
1546+ #### Event: 'checkContinue'
1547+ <!-- YAML
1548+ added: v8.5.0
1549+ -->
1550+
1551+ * ` request ` {http2.Http2ServerRequest}
1552+ * ` response ` {http2.Http2ServerResponse}
1553+
1554+ If a [ ` 'request' ` ] [ ] listener is registered or [ ` http2.createSecureServer() ` ] [ ]
1555+ is supplied a callback function, the ` 'checkContinue' ` event is emitted each
1556+ time a request with an HTTP ` Expect: 100-continue ` is received. If this event
1557+ is not listened for, the server will automatically respond with a status
1558+ ` 100 Continue ` as appropriate.
1559+
1560+ Handling this event involves calling [ ` response.writeContinue() ` ] [ ] if the client
1561+ should continue to send the request body, or generating an appropriate HTTP
1562+ response (e.g. 400 Bad Request) if the client should not continue to send the
1563+ request body.
1564+
1565+ Note that when this event is emitted and handled, the [ ` 'request' ` ] [ ] event will
1566+ not be emitted.
1567+
1568+ #### Event: 'request'
15841569<!-- YAML
15851570added: v8.4.0
15861571-->
15871572
1588- The ` 'sessionError' ` event is emitted when an ` 'error' ` event is emitted by
1589- an ` Http2Session ` object associated with the ` Http2SecureServer ` .
1573+ * ` request ` {http2.Http2ServerRequest}
1574+ * ` response ` {http2.Http2ServerResponse}
15901575
1591- #### Event: 'unknownProtocol'
1576+ Emitted each time there is a request. Note that there may be multiple requests
1577+ per session. See the [ Compatibility API] [ ] .
1578+
1579+ #### Event: 'session'
15921580<!-- YAML
15931581added: v8.4.0
15941582-->
15951583
1596- The ` 'unknownProtocol' ` event is emitted when a connecting client fails to
1597- negotiate an allowed protocol (i.e. HTTP/2 or HTTP/1.1). The event handler
1598- receives the socket for handling. If no listener is registered for this event,
1599- the connection is terminated. See the [ Compatibility API] [ ] .
1584+ The ` 'session' ` event is emitted when a new ` Http2Session ` is created by the
1585+ ` Http2SecureServer ` .
1586+
1587+ #### Event: 'sessionError'
1588+ <!-- YAML
1589+ added: v8.4.0
1590+ -->
1591+
1592+ The ` 'sessionError' ` event is emitted when an ` 'error' ` event is emitted by
1593+ an ` Http2Session ` object associated with the ` Http2SecureServer ` .
16001594
16011595#### Event: 'stream'
16021596<!-- YAML
@@ -1631,43 +1625,23 @@ server.on('stream', (stream, headers, flags) => {
16311625});
16321626```
16331627
1634- #### Event: 'request '
1628+ #### Event: 'timeout '
16351629<!-- YAML
16361630added: v8.4.0
16371631-->
16381632
1639- * ` request ` {http2.Http2ServerRequest}
1640- * ` response ` {http2.Http2ServerResponse}
1641-
1642- Emitted each time there is a request. Note that there may be multiple requests
1643- per session. See the [ Compatibility API] [ ] .
1633+ The ` 'timeout' ` event is emitted when there is no activity on the Server for
1634+ a given number of milliseconds set using ` http2secureServer.setTimeout() ` .
16441635
1645- #### Event: 'timeout '
1636+ #### Event: 'unknownProtocol '
16461637<!-- YAML
16471638added: v8.4.0
16481639-->
16491640
1650- #### Event: 'checkContinue'
1651- <!-- YAML
1652- added: v8.5.0
1653- -->
1654-
1655- * ` request ` {http2.Http2ServerRequest}
1656- * ` response ` {http2.Http2ServerResponse}
1657-
1658- If a [ ` 'request' ` ] [ ] listener is registered or [ ` http2.createSecureServer() ` ] [ ]
1659- is supplied a callback function, the ` 'checkContinue' ` event is emitted each
1660- time a request with an HTTP ` Expect: 100-continue ` is received. If this event
1661- is not listened for, the server will automatically respond with a status
1662- ` 100 Continue ` as appropriate.
1663-
1664- Handling this event involves calling [ ` response.writeContinue() ` ] [ ] if the client
1665- should continue to send the request body, or generating an appropriate HTTP
1666- response (e.g. 400 Bad Request) if the client should not continue to send the
1667- request body.
1668-
1669- Note that when this event is emitted and handled, the [ ` 'request' ` ] [ ] event will
1670- not be emitted.
1641+ The ` 'unknownProtocol' ` event is emitted when a connecting client fails to
1642+ negotiate an allowed protocol (i.e. HTTP/2 or HTTP/1.1). The event handler
1643+ receives the socket for handling. If no listener is registered for this event,
1644+ the connection is terminated. See the [ Compatibility API] [ ] .
16711645
16721646### http2.createServer(options[ , onRequestHandler] )
16731647<!-- YAML
0 commit comments