Skip to content

Commit 5b45eb5

Browse files
Peter Martonhekike
Peter Marton
authored andcommitted
feat(http2): add native HTTP/2 support
1 parent 6598949 commit 5b45eb5

14 files changed

+1792
-1500
lines changed

docs/_api/request.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ permalink: /docs/request-api/
4040
**Extends http.IncomingMessage**
4141

4242
Wraps all of the node
43-
[http.IncomingMessage](https://nodejs.org/api/http.html#http_http_incomingmessage)
43+
[http.IncomingMessage](https://nodejs.org/api/http.html)
4444
APIs, events and properties, plus the following.
4545

4646
### accepts
@@ -55,8 +55,8 @@ Otherwise the given type is matched by an exact match, and then subtypes.
5555

5656
**Examples**
5757

58-
_You may pass the subtype such as html which is then converted internally to
59-
text/html using the mime lookup table:_
58+
_You may pass the subtype such as html which is then converted internally
59+
to text/html using the mime lookup table:_
6060

6161
```javascript
6262
// Accept: text/html
@@ -95,8 +95,8 @@ Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
9595

9696
### getContentType
9797

98-
Returns the value of the content-type header. If a content-type is not set,
99-
this will return a default value of `application/octet-stream`
98+
Returns the value of the content-type header. If a content-type is not
99+
set, this will return a default value of `application/octet-stream`
100100

101101
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
102102

@@ -300,8 +300,8 @@ Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
300300
Start the timer for a request handler.
301301
By default, restify uses calls this automatically for all handlers
302302
registered in your handler chain.
303-
However, this can be called manually for nested functions inside the handler
304-
chain to record timing information.
303+
However, this can be called manually for nested functions inside the
304+
handler chain to record timing information.
305305

306306
**Parameters**
307307

@@ -310,8 +310,8 @@ chain to record timing information.
310310
**Examples**
311311

312312
_You must explicitly invoke
313-
endHandlerTimer() after invoking this function. Otherwise timing information
314-
will be inaccurate._
313+
endHandlerTimer() after invoking this function. Otherwise timing
314+
information will be inaccurate._
315315

316316
```javascript
317317
server.get('/', function fooHandler(req, res, next) {

docs/_api/response.md

+17-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ permalink: /docs/response-api/
2727
**Extends http.ServerResponse**
2828

2929
Wraps all of the node
30-
[http.ServerResponse](https://nodejs.org/docs/latest/api/http.html#http.ServerResponse)
30+
[http.ServerResponse](https://nodejs.org/docs/latest/api/http.html)
3131
APIs, events and properties, plus the following.
3232

3333
### cache
@@ -154,10 +154,10 @@ formatter based on the `content-type` header.
154154

155155
_You can use send() to wrap up all the usual writeHead(), write(), end()
156156
calls on the HTTP API of node.
157-
You can pass send either a `code` and `body`, or just a body. body can be an
158-
`Object`, a `Buffer`, or an `Error`.
159-
When you call `send()`, restify figures out how to format the response based
160-
on the `content-type`._
157+
You can pass send either a `code` and `body`, or just a body. body can be
158+
an `Object`, a `Buffer`, or an `Error`.
159+
When you call `send()`, restify figures out how to format the response
160+
based on the `content-type`._
161161

162162
```javascript
163163
res.send({hello: 'world'});
@@ -169,8 +169,8 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
169169

170170
### sendRaw
171171

172-
Like `res.send()`, but skips formatting. This can be useful when the payload
173-
has already been preformatted.
172+
Like `res.send()`, but skips formatting. This can be useful when the
173+
payload has already been preformatted.
174174
Sends the response object. pass through to internal `__send` that skips
175175
formatters entirely and sends the content as is.
176176

@@ -189,7 +189,8 @@ Uses `header()` underneath the hood, enabling multi-value headers.
189189

190190
**Parameters**
191191

192-
- `name` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the header or `Object` of headers
192+
- `name` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the header or
193+
`Object` of headers
193194
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** value of the header
194195

195196
**Examples**
@@ -236,13 +237,15 @@ Redirect is sugar method for redirecting.
236237
- `options.hostname` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** redirect location's hostname
237238
- `options.pathname` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** redirect location's pathname
238239
- `options.port` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** redirect location's port number
239-
- `options.query` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** redirect location's query string parameters
240-
- `options.overrideQuery` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** if true, `options.query` stomps over
241-
any existing query parameters on current URL.
242-
by default, will merge the two.
240+
- `options.query` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** redirect location's query string
241+
parameters
242+
- `options.overrideQuery` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** if true, `options.query`
243+
stomps over any existing query
244+
parameters on current URL.
245+
by default, will merge the two.
243246
- `options.permanent` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** if true, sets 301. defaults to 302.
244-
- `next` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** mandatory, to complete the response and trigger audit
245-
logger.
247+
- `next` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** mandatory, to complete the response and trigger
248+
audit logger.
246249

247250
**Examples**
248251

docs/_api/server.md

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Creates a new Server.
116116
response header, default is `restify`. Pass empty string to unset the header. (optional, default `false`)
117117
- `options.spdy` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Any options accepted by
118118
[node-spdy](https://github.com/indutny/node-spdy).
119+
- `options.http2` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Any options accepted by
120+
[http2.createSecureServer](https://nodejs.org/api/http2.html).
119121
- `options.handleUpgrades` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Hook the `upgrade` event
120122
from the node HTTP server, pushing `Connection: Upgrade` requests through the
121123
regular request handling chain. (optional, default `false`)

examples/http2/http2.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var path = require('path');
2+
var fs = require('fs');
3+
var bunyan = require('bunyan');
4+
var restify = require('../../lib');
5+
6+
var srv = restify.createServer({
7+
http2: {
8+
cert: fs.readFileSync(path.join(__dirname, './keys/http2-cert.pem')),
9+
key: fs.readFileSync(path.join(__dirname, './keys/http2-key.pem')),
10+
ca: fs.readFileSync(path.join(__dirname, 'keys/http2-csr.pem'))
11+
}
12+
});
13+
14+
srv.get('/', function(req, res, next) {
15+
res.send({ hello: 'world' });
16+
next();
17+
});
18+
19+
srv.on(
20+
'after',
21+
restify.plugins.auditLogger({
22+
event: 'after',
23+
body: true,
24+
log: bunyan.createLogger({
25+
name: 'audit',
26+
stream: process.stdout
27+
})
28+
})
29+
);
30+
31+
srv.listen(8080, function() {
32+
console.log('ready on %s', srv.url);
33+
});

examples/http2/keys/http2-cert.pem

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICHzCCAYgCCQCPPSUAa8QZojANBgkqhkiG9w0BAQUFADBUMQswCQYDVQQGEwJS
3+
VTETMBEGA1UECBMKU29tZS1TdGF0ZTENMAsGA1UEBxMET21zazEhMB8GA1UEChMY
4+
SW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMB4XDTExMDQwOTEwMDY0NVoXDTExMDUw
5+
OTEwMDY0NVowVDELMAkGA1UEBhMCUlUxEzARBgNVBAgTClNvbWUtU3RhdGUxDTAL
6+
BgNVBAcTBE9tc2sxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCB
7+
nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1bn25sPkv46wl70BffxradlkRd/x
8+
p5Xf8HDhPSfzNNctERYslXT2fX7Dmfd5w1XTVqqGqJ4izp5VewoVOHA8uavo3ovp
9+
gNWasil5zADWaM1T0nnV0RsFbZWzOTmm1U3D48K8rW3F5kOZ6f4yRq9QT1gF/gN7
10+
5Pt494YyYyJu/a8CAwEAATANBgkqhkiG9w0BAQUFAAOBgQBuRZisIViI2G/R+w79
11+
vk21TzC/cJ+O7tKsseDqotXYTH8SuimEH5IWcXNgnWhNzczwN8s2362NixyvCipV
12+
yd4wzMpPbjIhnWGM0hluWZiK2RxfcqimIBjDParTv6CMUIuwGQ257THKY8hXGg7j
13+
Uws6Lif3P9UbsuRiYPxMgg98wg==
14+
-----END CERTIFICATE-----
15+

examples/http2/keys/http2-csr.pem

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-----BEGIN CERTIFICATE REQUEST-----
2+
MIIBkzCB/QIBADBUMQswCQYDVQQGEwJSVTETMBEGA1UECBMKU29tZS1TdGF0ZTEN
3+
MAsGA1UEBxMET21zazEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRk
4+
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVufbmw+S/jrCXvQF9/Gtp2WRF
5+
3/Gnld/wcOE9J/M01y0RFiyVdPZ9fsOZ93nDVdNWqoaoniLOnlV7ChU4cDy5q+je
6+
i+mA1ZqyKXnMANZozVPSedXRGwVtlbM5OabVTcPjwrytbcXmQ5np/jJGr1BPWAX+
7+
A3vk+3j3hjJjIm79rwIDAQABoAAwDQYJKoZIhvcNAQEFBQADgYEAiNWhz6EppIVa
8+
FfUaB3sLeqfamb9tg9kBHtvqj/FJni0snqms0kPWaTySEPHZF0irIb7VVdq/sVCb
9+
3gseMVSyoDvPJ4lHC3PXqGQ7kM1mIPhDnR/4HDA3BhlGhTXSDIHgZnvI+HMBdsyC
10+
hC3dz5odyKqe4nmoofomALkBL9t4H8s=
11+
-----END CERTIFICATE REQUEST-----
12+

examples/http2/keys/http2-key.pem

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIICXAIBAAKBgQDVufbmw+S/jrCXvQF9/Gtp2WRF3/Gnld/wcOE9J/M01y0RFiyV
3+
dPZ9fsOZ93nDVdNWqoaoniLOnlV7ChU4cDy5q+jei+mA1ZqyKXnMANZozVPSedXR
4+
GwVtlbM5OabVTcPjwrytbcXmQ5np/jJGr1BPWAX+A3vk+3j3hjJjIm79rwIDAQAB
5+
AoGAAv2QI9h32epQND9TxwSCKD//dC7W/cZOFNovfKCTeZjNK6EIzKqPTGA6smvR
6+
C1enFl5adf+IcyWqAoe4lkqTvurIj+2EhtXdQ8DBlVuXKr3xvEFdYxXPautdTCF6
7+
KbXEyS/s1TZCRFjYftvCrXxc3pK45AQX/wg7z1K+YB5pyIECQQD0OJvLoxLYoXAc
8+
FZraIOZiDsEbGuSHqoCReFXH75EC3+XGYkH2bQ/nSIZ0h1buuwQ/ylKXOlTPT3Qt
9+
Xm1OQEBvAkEA4AjWsIO/rRpOm/Q2aCrynWMpoUXTZSbL2yGf8pxp/+8r2br5ier0
10+
M1LeBb/OPY1+k39NWLXxQoo64xoSFYk2wQJAd2wDCwX4HkR7HNCXw1hZL9QFK6rv
11+
20NN0VSlpboJD/3KT0MW/FiCcVduoCbaJK0Au+zEjDyy4hj5N4I4Mw6KMwJAXVAx
12+
I+psTsxzS4/njXG+BgIEl/C+gRYsuMQDnAi8OebDq/et8l0Tg8ETSu++FnM18neG
13+
ntmBeMacinUUbTXuwQJBAJp/onZdsMzeVulsGrqR1uS+Lpjc5Q1gt5ttt2cxj91D
14+
rio48C/ZvWuKNE8EYj2ALtghcVKRvgaWfOxt2GPguGg=
15+
-----END RSA PRIVATE KEY-----
16+

0 commit comments

Comments
 (0)