Package detail

http2

molnarg230kMITdeprecated3.3.7

Use the built-in module in node 9.0.0 or newer, instead

An HTTP/2 client and server implementation

http, http2, client, server

readme

node-http2

An HTTP/2 (RFC 7540) client and server implementation for node.js.

Travis CI status

Installation

npm install http2

API

The API is very similar to the standard node.js HTTPS API. The goal is the perfect API compatibility, with additional HTTP2 related extensions (like server push).

Detailed API documentation is primarily maintained in the lib/http.js file and is available in the wiki as well.

Examples

Using as a server

var options = {
  key: fs.readFileSync('./example/localhost.key'),
  cert: fs.readFileSync('./example/localhost.crt')
};

require('http2').createServer(options, function(request, response) {
  response.end('Hello world!');
}).listen(8080);

Using as a client

require('http2').get('https://localhost:8080/', function(response) {
  response.pipe(process.stdout);
});

Simple static file server

An simple static file server serving up content from its own directory is available in the example directory. Running the server:

$ node ./example/server.js

Simple command line client

An example client is also available. Downloading the server's own source code from the server:

$ node ./example/client.js 'https://localhost:8080/server.js' >/tmp/server.js

Server push

For a server push example, see the source code of the example server and client.

Status

  • ALPN is only supported in node.js >= 5.0
  • Upgrade mechanism to start HTTP/2 over unencrypted channel is not implemented yet (issue #4)
  • Other minor features found in this list are not implemented yet

Development

Development dependencies

There's a few library you will need to have installed to do anything described in the following sections. After installing/cloning node-http2, run npm install in its directory to install development dependencies.

Used libraries:

For pretty printing logs, you will also need a global install of bunyan (npm install -g bunyan).

Developer documentation

The developer documentation is generated from the source code using docco and can be viewed online here. If you'd like to have an offline copy, just run npm run-script doc.

Running the tests

It's easy, just run npm test. The tests are written in BDD style, so they are a good starting point to understand the code.

Test coverage

To generate a code coverage report, run npm test --coverage (which runs very slowly, be patient). Code coverage summary as of version 3.0.1:

Statements   : 92.09% ( 1759/1910 )
Branches     : 82.56% ( 696/843 )
Functions    : 91.38% ( 212/232 )
Lines        : 92.17% ( 1753/1902 )

There's a hosted version of the detailed (line-by-line) coverage report here.

Logging

Logging is turned off by default. You can turn it on by passing a bunyan logger as log option when creating a server or agent.

When using the example server or client, it's very easy to turn logging on: set the HTTP2_LOG environment variable to fatal, error, warn, info, debug or trace (the logging level). To log every single incoming and outgoing data chunk, use HTTP2_LOG_DATA=1 besides HTTP2_LOG=trace. Log output goes to the standard error output. If the standard error is redirected into a file, then the log output is in bunyan's JSON format for easier post-mortem analysis.

Running the example server and client with info level logging output:

$ HTTP2_LOG=info node ./example/server.js
$ HTTP2_LOG=info node ./example/client.js 'https://localhost:8080/server.js' >/dev/null

Contributors

The co-maintainer of the project is Nick Hurley.

Code contributions are always welcome! People who contributed to node-http2 so far:

Special thanks to Google for financing the development of this module as part of their Summer of Code program (project: HTTP/2 prototype server implementation), and Nick Hurley of Mozilla, my GSoC mentor, who helped with regular code review and technical advices.

License

The MIT License

Copyright (C) 2013 Gábor Molnár gabor@molnar.es

changelog

Version history

3.3.7 (2017-09-21)

  • Mark as incompatible with node >= 9.0.0 (to encourage using the built-in http2 module available by default in node >= 9.0.0).

3.3.6 (2016-09-16)

  • We were not appropriately sending HPACK context updates when receiving SETTINGS_HEADER_TABLE_SIZE. This release fixes that bug.

3.3.5 (2016-09-06)

3.3.4 (2016-04-22)

3.3.3 (2016-04-21)

3.3.2 (2016-01-11)

  • Fix an incompatibility with Firefox (issue 167)

3.3.1 (2016-01-11)

  • Fix some DoS bugs (issues 145, 146, 147, and 148)

3.3.0 (2016-01-10)

  • Bugfix updates from pull requests

3.2.0 (2015-02-19)

  • Update ALPN token to final RFC version (h2).
  • Update altsvc implementation to draft 06: [draft-ietf-httpbis-alt-svc-06]

3.1.2 (2015-02-17)

  • Update the example server to have a safe push example.

3.1.1 (2015-01-29)

  • Bugfix release.
  • Fixes an issue sending a push promise that is large enough to fill the frame (#93).

3.1.0 (2014-12-11)

  • Upgrade to the latest draft: draft-ietf-httpbis-http2-16
    • This involves some state transition changes that are technically incompatible with draft-14. If you need to be assured to interop on -14, continue using 3.0.1

3.0.1 (2014-11-20)

  • Bugfix release.
  • Fixed #81 and #87
  • Fixed a bug in flow control (without GitHub issue)

3.0.0 (2014-08-25)

  • Re-join node-http2 and node-http2-protocol into one repository
  • API Changes
    • The default versions of createServer, request, and get now enforce TLS-only
    • The raw versions of createServer, request, and get are now under http2.raw instead of http2
    • What was previously in the http2-protocol repository/module is now available under http2.protocol from this repo/module
    • http2-protocol.ImplementedVersion is now http2.protocol.VERSION (the ALPN token)

2.7.1 (2014-08-01)

  • Require protocol 0.14.1 (bugfix release)

2.7.0 (2014-07-31)

2.6.0 (2014-06-18)

2.5.3 (2014-06-15)

  • Exposing API to send ALTSVC frames

2.5.2 (2014-05-25)

  • Fix a bug that occurs when the ALPN negotiation is unsuccessful

2.5.1 (2014-05-25)

  • Support for node 0.11.x
  • New cipher suite priority list with comformant ciphers on the top (only available in node >=0.11.x)

2.5.0 (2014-04-24)

2.4.0 (2014-04-16)

2.3.0 (2014-03-12)

2.2.0 (2013-12-25)

2.1.1 (2013-12-21)

2.1.0 (2013-11-10)

2.0.0 (2013-11-09)

  • Splitting out everything that is not related to negotiating HTTP2 or the node-like HTTP API. These live in separate module from now on: http2-protocol.
  • The only backwards incompatible change: the Endpoint class is not exported anymore. Use the http2-protocol module if you want to use this low level interface.
  • Tarball

1.0.1 (2013-10-14)

  • Support for ALPN if node supports it (currently needs a custom build)
  • Fix for a few small issues
  • Tarball

1.0.0 (2013-09-23)

  • Exporting Endpoint class
  • Support for 'filters' in Endpoint
  • The last time-based release
  • Tarball

0.4.1 (2013-09-15)

  • Major performance improvements
  • Minor improvements to error handling
  • Blog post
  • Tarball

0.4.0 (2013-09-09)

0.3.1 (2013-09-03)

0.3.0 (2013-08-27)

  • Support for prioritization
  • Small API compatibility improvements (compatibility with the standard node.js HTTP API)
  • Minor push API change
  • Ability to pass an external bunyan logger when creating a Server or Agent
  • Blog post
  • Tarball

0.2.1 (2013-08-20)

  • Fixing a flow control bug
  • Tarball

0.2.0 (2013-08-19)

  • Exposing server push in the public API
  • Connection pooling when operating as client
  • Much better API compatibility with the standard node.js HTTPS module
  • Logging improvements
  • Blog post
  • Tarball

0.1.1 (2013-08-12)

  • Lots of bugfixes
  • Proper flow control for outgoing frames
  • Basic flow control for incoming frames
  • Blog post
  • Tarball

0.1.0 (2013-08-06)

  • First release with public API (similar to the standard node HTTPS module)
  • Support for NPN negotiation (no ALPN or Upgrade yet)
  • Stream number limitation is in place
  • Push streams works but not exposed yet in the public API
  • Blog post
  • Tarball

0.0.6 (2013-07-19)

  • Connection and Endpoint classes are usable, but not yet ready
  • Addition of an exmaple server and client
  • Using istanbul for measuring code coverage
  • Blog post
  • Tarball

0.0.5 (2013-07-14)

0.0.4 (2013-07-08)

0.0.3 (2013-07-03)

0.0.2 (2013-07-01)

  • Frame serialization and deserialization ready and updated to match the newest spec
  • Header compression implementation started
  • Blog post
  • Tarball

0.0.1 (2013-06-23)