• Jump To … +
    compressor.js connection.js endpoint.js flow.js framer.js http.js index.js stream.js
  • index.js

  • ¶

    node-http2 is an HTTP/2 (draft 04) implementation for node.js.

    The main building blocks are mainly node.js streams that are connected through pipes.

    The main components are:

    • http.js: the top layer that presents an API very similar to the standard node.js HTTPS module (which is in turn very similar to the HTTP module).

    • Endpoint: represents an HTTP/2 endpoint (client or server). It's responsible for the the first part of the handshake process (sending/receiving the connection header) and manages other components (framer, compressor, connection, streams) that make up a client or server.

    • Connection: multiplexes the active HTTP/2 streams, manages connection lifecycle and settings, and responsible for enforcing the connection level limits (flow control, initiated stream limit)

    • Stream: implementation of the HTTP/2 stream concept. Implements the stream state machine defined by the standard, provides management methods and events for using the stream (sending/receiving headers, data, etc.), and enforces stream level constraints (flow control, sending only legal frames).

    • Flow: implements flow control for Connection and Stream as parent class.

    • Compressor and Decompressor: compression and decompression of HEADER and PUSH_PROMISE frames

    • Serializer and Deserializer: the lowest layer in the stack that transforms between the binary and the JavaScript object representation of HTTP/2 frames

    module.exports   = require('./http');
    
    /*
                        API user
    
                     |            ^
                     |            |
     +---------------|------------|--------------------------------------------------------+
     |               |            |        Server/Agent                                    |
     |               v            |                                                        |
     |          +----------+ +----------+                                                  |
     |          | Outgoing | | Incoming |                                                  |
     |          | req/res. | | req/res. |                                                  |
     |          +----------+ +----------+                                                  |
     |               |            ^                                                        |
     |   +-----------|------------|---------------------------------------+   +-----       |
     |   |           |            |   Endpoint                            |   |            |
     |   |           |            |                                       |   |            |
     |   |   +-------|------------|-----------------------------------+   |   |            |
     |   |   |       |            |  Connection                       |   |   |            |
     |   |   |       v            |                                   |   |   |            |
     |   |   |  +-----------------------+  +--------------------      |   |   |            |
     |   |   |  |        Stream         |  |         Stream      ...  |   |   |            |
     |   |   |  +-----------------------+  +--------------------      |   |   |            |
     |   |   |       |            ^              |            ^       |   |   |            |
     |   |   |       v            |              v            |       |   |   |            |
     |   |   |       +------------+--+--------+--+------------+- ...  |   |   |            |
     |   |   |                       |        ^                       |   |   |            |
     |   |   |                       |        |                       |   |   |      ...   |
     |   |   +-----------------------|--------|-----------------------+   |   |            |
     |   |                           |        |                           |   |            |
     |   |                           v        |                           |   |            |
     |   |   +--------------------------+  +--------------------------+   |   |            |
     |   |   |        Compressor        |  |       Decompressor       |   |   |            |
     |   |   +--------------------------+  +--------------------------+   |   |            |
     |   |                           |        ^                           |   |            |
     |   |                           v        |                           |   |            |
     |   |   +--------------------------+  +--------------------------+   |   |            |
     |   |   |        Serializer        |  |       Deserializer       |   |   |            |
     |   |   +--------------------------+  +--------------------------+   |   |            |
     |   |                           |        ^                           |   |            |
     |   +---------------------------|--------|---------------------------+   +-----       |
     |                               |        |                                            |
     |                               v        |                                            |
     |   +----------------------------------------------------------------+   +-----       |
     |   |                           TCP stream                           |   |      ...   |
     |   +----------------------------------------------------------------+   +-----       |
     |                                                                                     |
     +-------------------------------------------------------------------------------------+
    
    */