| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,8 +19,8 @@ compatibility with the existing [HTTP/1][] module API. However, | |||
| 19 | 19 | the [Compatibility API][] is. | |
| 20 | 20 | ||
| 21 | 21 | The `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. | ||
| 24 | 24 | ||
| 25 | 25 | ### Server-side example | |
| 26 | 26 | ||
@@ -36,7 +36,6 @@ const server = http2.createSecureServer({ | |||
| 36 | 36 | cert: fs.readFileSync('localhost-cert.pem') | |
| 37 | 37 | }); | |
| 38 | 38 | server.on('error', (err) => console.error(err)); | |
| 39 | - server.on('socketError', (err) => console.error(err)); | ||
| 40 | 39 | ||
| 41 | 40 | server.on('stream', (stream, headers) => { | |
| 42 | 41 | // stream is a Duplex | |
@@ -68,7 +67,6 @@ const client = http2.connect('https://localhost:8443', { | |||
| 68 | 67 | ca: fs.readFileSync('localhost-cert.pem') | |
| 69 | 68 | }); | |
| 70 | 69 | client.on('error', (err) => console.error(err)); | |
| 71 | - client.on('socketError', (err) => console.error(err)); | ||
| 72 | 70 | ||
| 73 | 71 | const req = client.request({ ':path': '/' }); | |
| 74 | 72 | ||
@@ -479,44 +477,6 @@ Used to set a callback function that is called when there is no activity on | |||
| 479 | 477 | the `Http2Session` after `msecs` milliseconds. The given `callback` is | |
| 480 | 478 | registered as a listener on the `'timeout'` event. | |
| 481 | 479 | ||
| 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 | - | ||
| 520 | 480 | #### http2session.socket | |
| 521 | 481 | <!-- YAML | |
| 522 | 482 | added: v8.4.0 | |
@@ -686,19 +646,23 @@ added: v8.4.0 | |||
| 686 | 646 | added: v9.4.0 | |
| 687 | 647 | --> | |
| 688 | 648 | ||
| 649 | + * `alt`: {string} | ||
| 650 | + * `origin`: {string} | ||
| 651 | + * `streamId`: {number} | ||
| 652 | + | ||
| 689 | 653 | The `'altsvc'` event is emitted whenever an `ALTSVC` frame is received by | |
| 690 | 654 | the 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 | ||
| 692 | 656 | be an empty string. | |
| 693 | 657 | ||
| 694 | 658 | ```js | |
| 695 | 659 | const http2 = require('http2'); | |
| 696 | 660 | const client = http2.connect('https://example.org'); | |
| 697 | 661 | ||
| 698 | - client.on('altsvc', (alt, origin, stream) => { | ||
| 662 | + client.on('altsvc', (alt, origin, streamId) => { | ||
| 699 | 663 | console.log(alt); | |
| 700 | 664 | console.log(origin); | |
| 701 | - console.log(stream); | ||
| 665 | + console.log(streamId); | ||
| 702 | 666 | }); | |
| 703 | 667 | ``` | |
| 704 | 668 | ||
@@ -1472,10 +1436,9 @@ added: v8.4.0 | |||
| 1472 | 1436 | ||
| 1473 | 1437 | * Extends: {net.Server} | |
| 1474 | 1438 | ||
| 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. | ||
| 1479 | 1442 | ||
| 1480 | 1443 | #### Event: 'checkContinue' | |
| 1481 | 1444 | <!-- YAML | |
@@ -1580,23 +1543,54 @@ added: v8.4.0 | |||
| 1580 | 1543 | ||
| 1581 | 1544 | * Extends: {tls.Server} | |
| 1582 | 1545 | ||
| 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' | ||
| 1584 | 1569 | <!-- YAML | |
| 1585 | 1570 | added: v8.4.0 | |
| 1586 | 1571 | --> | |
| 1587 | 1572 | ||
| 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} | ||
| 1590 | 1575 | ||
| 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' | ||
| 1592 | 1580 | <!-- YAML | |
| 1593 | 1581 | added: v8.4.0 | |
| 1594 | 1582 | --> | |
| 1595 | 1583 | ||
| 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`. | ||
| 1600 | 1594 | ||
| 1601 | 1595 | #### Event: 'stream' | |
| 1602 | 1596 | <!-- YAML | |
@@ -1631,43 +1625,23 @@ server.on('stream', (stream, headers, flags) => { | |||
| 1631 | 1625 | }); | |
| 1632 | 1626 | ``` | |
| 1633 | 1627 | ||
| 1634 | - #### Event: 'request' | ||
| 1628 | + #### Event: 'timeout' | ||
| 1635 | 1629 | <!-- YAML | |
| 1636 | 1630 | added: v8.4.0 | |
| 1637 | 1631 | --> | |
| 1638 | 1632 | ||
| 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()`. | ||
| 1644 | 1635 | ||
| 1645 | - #### Event: 'timeout' | ||
| 1636 | + #### Event: 'unknownProtocol' | ||
| 1646 | 1637 | <!-- YAML | |
| 1647 | 1638 | added: v8.4.0 | |
| 1648 | 1639 | --> | |
| 1649 | 1640 | ||
| 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][]. | ||
| 1671 | 1645 | ||
| 1672 | 1646 | ### http2.createServer(options[, onRequestHandler]) | |
| 1673 | 1647 | <!-- YAML | |
| Back | FazBrowse Home | New Git URL |
0 commit comments