|
1 node-http2 |
|
2 ========== |
|
3 |
|
4 An HTTP/2 ([draft-ietf-httpbis-http2-10](http://tools.ietf.org/html/draft-ietf-httpbis-http2-10)) |
|
5 client and server implementation for node.js. |
|
6 |
|
7 Installation |
|
8 ------------ |
|
9 |
|
10 ``` |
|
11 npm install http2 |
|
12 ``` |
|
13 |
|
14 API |
|
15 --- |
|
16 |
|
17 The API is very similar to the [standard node.js HTTPS API](http://nodejs.org/api/https.html). The |
|
18 goal is the perfect API compatibility, with additional HTTP2 related extensions (like server push). |
|
19 |
|
20 Detailed API documentation is primarily maintained in the `lib/http.js` file and is [available in |
|
21 the wiki](https://github.com/molnarg/node-http2/wiki/Public-API) as well. |
|
22 |
|
23 Examples |
|
24 -------- |
|
25 |
|
26 ### Using as a server ### |
|
27 |
|
28 ```javascript |
|
29 var options = { |
|
30 key: fs.readFileSync('./example/localhost.key'), |
|
31 cert: fs.readFileSync('./example/localhost.crt') |
|
32 }; |
|
33 |
|
34 require('http2').createServer(options, function(request, response) { |
|
35 response.end('Hello world!'); |
|
36 }).listen(8080); |
|
37 ``` |
|
38 |
|
39 ### Using as a client ### |
|
40 |
|
41 ```javascript |
|
42 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; |
|
43 |
|
44 require('http2').get('https://localhost:8080/', function(response) { |
|
45 response.pipe(process.stdout); |
|
46 }); |
|
47 ``` |
|
48 |
|
49 ### Simple static file server ### |
|
50 |
|
51 An simple static file server serving up content from its own directory is available in the `example` |
|
52 directory. Running the server: |
|
53 |
|
54 ```bash |
|
55 $ node ./example/server.js |
|
56 ``` |
|
57 |
|
58 ### Simple command line client ### |
|
59 |
|
60 An example client is also available. Downloading the server's own source code from the server: |
|
61 |
|
62 ```bash |
|
63 $ node ./example/client.js 'https://localhost:8080/server.js' >/tmp/server.js |
|
64 ``` |
|
65 |
|
66 ### Server push ### |
|
67 |
|
68 For a server push example, see the source code of the example |
|
69 [server](https://github.com/molnarg/node-http2/blob/master/example/server.js) and |
|
70 [client](https://github.com/molnarg/node-http2/blob/master/example/client.js). |
|
71 |
|
72 Status |
|
73 ------ |
|
74 |
|
75 * ALPN is not yet supported in node.js (see |
|
76 [this issue](https://github.com/joyent/node/issues/5945)). For ALPN support, you will have to use |
|
77 [Shigeki Ohtsu's node.js fork](https://github.com/shigeki/node/tree/alpn_support) until this code |
|
78 gets merged upstream. |
|
79 * Upgrade mechanism to start HTTP/2 over unencrypted channel is not implemented yet |
|
80 (issue [#4](https://github.com/molnarg/node-http2/issues/4)) |
|
81 * Other minor features found in |
|
82 [this list](https://github.com/molnarg/node-http2/issues?labels=feature) are not implemented yet |
|
83 |
|
84 Development |
|
85 ----------- |
|
86 |
|
87 ### Development dependencies ### |
|
88 |
|
89 There's a few library you will need to have installed to do anything described in the following |
|
90 sections. After installing/cloning node-http2, run `npm install` in its directory to install |
|
91 development dependencies. |
|
92 |
|
93 Used libraries: |
|
94 |
|
95 * [mocha](http://visionmedia.github.io/mocha/) for tests |
|
96 * [chai](http://chaijs.com/) for assertions |
|
97 * [istanbul](https://github.com/gotwarlost/istanbul) for code coverage analysis |
|
98 * [docco](http://jashkenas.github.io/docco/) for developer documentation |
|
99 * [bunyan](https://github.com/trentm/node-bunyan) for logging |
|
100 |
|
101 For pretty printing logs, you will also need a global install of bunyan (`npm install -g bunyan`). |
|
102 |
|
103 ### Developer documentation ### |
|
104 |
|
105 The developer documentation is generated from the source code using docco and can be viewed online |
|
106 [here](http://molnarg.github.io/node-http2/doc/). If you'd like to have an offline copy, just run |
|
107 `npm run-script doc`. |
|
108 |
|
109 ### Running the tests ### |
|
110 |
|
111 It's easy, just run `npm test`. The tests are written in BDD style, so they are a good starting |
|
112 point to understand the code. |
|
113 |
|
114 ### Test coverage ### |
|
115 |
|
116 To generate a code coverage report, run `npm test --coverage` (which runs very slowly, be patient). |
|
117 Code coverage summary as of version 1.0.1: |
|
118 ``` |
|
119 Statements : 93.26% ( 1563/1676 ) |
|
120 Branches : 84.85% ( 605/713 ) |
|
121 Functions : 94.81% ( 201/212 ) |
|
122 Lines : 93.23% ( 1557/1670 ) |
|
123 ``` |
|
124 |
|
125 There's a hosted version of the detailed (line-by-line) coverage report |
|
126 [here](http://molnarg.github.io/node-http2/coverage/lcov-report/lib/). |
|
127 |
|
128 ### Logging ### |
|
129 |
|
130 Logging is turned off by default. You can turn it on by passing a bunyan logger as `log` option when |
|
131 creating a server or agent. |
|
132 |
|
133 When using the example server or client, it's very easy to turn logging on: set the `HTTP2_LOG` |
|
134 environment variable to `fatal`, `error`, `warn`, `info`, `debug` or `trace` (the logging level). |
|
135 To log every single incoming and outgoing data chunk, use `HTTP2_LOG_DATA=1` besides |
|
136 `HTTP2_LOG=trace`. Log output goes to the standard error output. If the standard error is redirected |
|
137 into a file, then the log output is in bunyan's JSON format for easier post-mortem analysis. |
|
138 |
|
139 Running the example server and client with `info` level logging output: |
|
140 |
|
141 ```bash |
|
142 $ HTTP2_LOG=info node ./example/server.js |
|
143 ``` |
|
144 |
|
145 ```bash |
|
146 $ HTTP2_LOG=info node ./example/client.js 'http://localhost:8080/server.js' >/dev/null |
|
147 ``` |
|
148 |
|
149 Contributors |
|
150 ------------ |
|
151 |
|
152 Code contributions are always welcome! People who contributed to node-http2 so far: |
|
153 |
|
154 * Nick Hurley |
|
155 * Mike Belshe |
|
156 |
|
157 Special thanks to Google for financing the development of this module as part of their [Summer of |
|
158 Code program](https://developers.google.com/open-source/soc/) (project: [HTTP/2 prototype server |
|
159 implementation](https://google-melange.appspot.com/gsoc/project/google/gsoc2013/molnarg/5001)), and |
|
160 Nick Hurley of Mozilla, my GSoC mentor, who helped with regular code review and technical advices. |
|
161 |
|
162 License |
|
163 ------- |
|
164 |
|
165 The MIT License |
|
166 |
|
167 Copyright (C) 2013 Gábor Molnár <gabor@molnar.es> |