From e725b635a5cf7f2c600a6c6961efe15b0e0d800e Mon Sep 17 00:00:00 2001 From: Zack McCartney Date: Thu, 9 Nov 2017 10:26:25 -0500 Subject: [PATCH 1/4] Update deps and instructions for hapi v.16 scrub --- .gitignore | 1 + .travis.yml | 1 + API.md | 18 ++++++++++++++++++ README.md | 23 ++++------------------- package.json | 10 +++++----- 5 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 API.md diff --git a/.gitignore b/.gitignore index 3c3629e..d5f19d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +package-lock.json diff --git a/.travis.yml b/.travis.yml index b253645..06ff096 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,6 @@ language: node_js node_js: - "4" - "6" + - "8" after_script: "npm run coveralls" diff --git a/API.md b/API.md new file mode 100644 index 0000000..016ab47 --- /dev/null +++ b/API.md @@ -0,0 +1,18 @@ +## API +### The plugin +You should register Underdog in any plugin that would like to take advantage of its features; it does not take any options. Underdog specifies the `once` [plugin attribute](http://hapijs.com/api#plugins), which means hapi will ensure it is not registered multiple times to the same connection. + +Note, Underdog utilizes an `onPreResponse` extension to finalize server-push, so if you modify the response in an `onPreResponse` extension and would like that response to push additional resources, you must specify `{ before: 'underdog' }` as an option when calling [`server.ext()`](http://hapijs.com/api#serverextevent-method-options). + +### `reply.push([response], path, [headers])` + - `response` - the hapi [response](http://hapijs.com/api#response-object) for which you'd like to push additional resources. Should not be an error response. When this argument is omitted Underdog will attempt to use the request's currently set response, which will fail with an error if there is no such response. + - `path` - the path to another resource living on the same connection as the current request that you'd like to server-push. If the path is relative (does not begin with `/`) then it is adjusted based upon the relevant [realm's](http://hapijs.com/api#serverrealm) route prefix. + - `headers` - any headers that you would like to add to the push-request for this resource. By default a user-agent header is automatically added to match the user-agent of the originating request. + + Note that when push-requests are resolved credentials from the originating request will be used, and that routes marked as `isInternal` are accessible. + +## Extras + - The HTTP/2 spec ([here](http://httpwg.org/specs/rfc7540.html)) + - The `http2` node module ([here](https://github.com/molnarg/node-http2)) + - The `spdy` (also implementing HTTP/2) node module ([here](https://github.com/indutny/node-spdy)) + - For debugging HTTP/2 in Chrome, see `chrome://net-internals/#http2` diff --git a/README.md b/README.md index ebcdf17..1b7392e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,11 @@ HTTP/2 server-push for hapi [![Build Status](https://travis-ci.org/devinivy/underdog.svg?branch=master)](https://travis-ci.org/devinivy/underdog) [![Coverage Status](https://coveralls.io/repos/devinivy/underdog/badge.svg?branch=master&service=github)](https://coveralls.io/github/devinivy/underdog?branch=master) +Lead Maintainer - [Devin Ivy](https://github.com/devinivy) + ## Usage +> See also the [API Reference](API.md) + Underdog brings [HTTP/2 server-push](http://httpwg.org/specs/rfc7540.html#PushResources) to hapijs. The way it works is that you specify paths to resources on the same connection as the current request that you'd like to push alongside a particular response. This is achieved with a call to the reply decoration [`reply.push()`](#replypushresponse-path-headers). Before hapi responds to the original request, those push-requests will be made internally and their results will be streamed to the client as push-responses. Even pushed resources can specify additional resources to push. You can't make this stuff up! ### Example @@ -65,22 +69,3 @@ server.register(Underdog, (err) => { ### Compatibility To use Underdog your hapi [connections](http://hapijs.com/api#serverconnectionoptions) must be provided a `listener` adherent to the HTTP/2 protocol. Currently Underdog is compatible with HTTP/2 listeners created with versions ≥3.4.0 and <4 of [node-spdy](https://github.com/indutny/node-spdy) and 3.x.x of [node-http2](https://github.com/molnarg/node-http2). - -## API -### The plugin -You should register Underdog in any plugin that would like to take advantage of its features; it does not take any options. Underdog specifies the `once` [plugin attribute](http://hapijs.com/api#plugins), which means hapi will ensure it is not registered multiple times to the same connection. - -Note, Underdog utilizes an `onPreResponse` extension to finalize server-push, so if you modify the response in an `onPreResponse` extension and would like that response to push additional resources, you must specify `{ before: 'underdog' }` as an option when calling [`server.ext()`](http://hapijs.com/api#serverextevent-method-options). - -### `reply.push([response], path, [headers])` - - `response` - the hapi [response](http://hapijs.com/api#response-object) for which you'd like to push additional resources. Should not be an error response. When this argument is omitted Underdog will attempt to use the request's currently set response, which will fail with an error if there is no such response. - - `path` - the path to another resource living on the same connection as the current request that you'd like to server-push. If the path is relative (does not begin with `/`) then it is adjusted based upon the relevant [realm's](http://hapijs.com/api#serverrealm) route prefix. - - `headers` - any headers that you would like to add to the push-request for this resource. By default a user-agent header is automatically added to match the user-agent of the originating request. - - Note that when push-requests are resolved credentials from the originating request will be used, and that routes marked as `isInternal` are accessible. - -## Extras - - The HTTP/2 spec ([here](http://httpwg.org/specs/rfc7540.html)) - - The `http2` node module ([here](https://github.com/molnarg/node-http2)) - - The `spdy` (also implementing HTTP/2) node module ([here](https://github.com/indutny/node-spdy)) - - For debugging HTTP/2 in Chrome, see `chrome://net-internals/#http2` diff --git a/package.json b/package.json index a53802d..c14ff3c 100644 --- a/package.json +++ b/package.json @@ -34,15 +34,15 @@ "items": "2.x.x" }, "peerDependencies": { - "hapi": ">=10 <16" + "hapi": ">=10 <17" }, "devDependencies": { - "boom": "4.x.x", - "code": "3.x.x", - "coveralls": "2.x.x", + "boom": "6.x.x", + "code": "4.x.x", + "coveralls": "3.x.x", "hapi": "15.x.x", "http2": "3.x.x", - "lab": "11.x.x", + "lab": "14.x.x", "spdy": ">=3.4.0 <4" } } From a953e0e39dd750c27660cd5243ff99d30caef5f4 Mon Sep 17 00:00:00 2001 From: Zack McCartney Date: Thu, 9 Nov 2017 10:31:00 -0500 Subject: [PATCH 2/4] Removed next calls (linter reported no-undef errors) --- test/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index bb71aaf..bf6372a 100644 --- a/test/index.js +++ b/test/index.js @@ -486,7 +486,7 @@ describe('Underdog', () => { srv.stop(done); }); - request.on('push', () => next(new Error('Should not make it here'))); + request.on('push', () => new Error('Should not make it here')); }); }); @@ -531,7 +531,7 @@ describe('Underdog', () => { srv.stop(done); }); - request.on('push', () => next(new Error('Should not make it here'))); + request.on('push', () => new Error('Should not make it here')); }); }); From 90f9e675ad6e880ef83ef5af897adc711b4ae6e2 Mon Sep 17 00:00:00 2001 From: Zack McCartney Date: Thu, 9 Nov 2017 10:53:17 -0500 Subject: [PATCH 3/4] Massage dependencies for node versions compatibility --- .travis.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 06ff096..0edd34a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,6 @@ language: node_js node_js: - "4" - "6" - - "8" + - "8.7.0" after_script: "npm run coveralls" diff --git a/package.json b/package.json index c14ff3c..d19f57d 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "hapi": ">=10 <17" }, "devDependencies": { - "boom": "6.x.x", + "boom": "5.x.x", "code": "4.x.x", "coveralls": "3.x.x", "hapi": "15.x.x", From bb70ac9e09e0fe28403c38c3c267f6db21d330fc Mon Sep 17 00:00:00 2001 From: Zack McCartney Date: Thu, 9 Nov 2017 11:34:59 -0500 Subject: [PATCH 4/4] Code review revisions --- package.json | 2 +- test/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d19f57d..2d6ff40 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "items": "2.x.x" }, "peerDependencies": { - "hapi": ">=10 <17" + "hapi": ">=10 <16" }, "devDependencies": { "boom": "5.x.x", diff --git a/test/index.js b/test/index.js index bf6372a..40d1f3b 100644 --- a/test/index.js +++ b/test/index.js @@ -486,7 +486,7 @@ describe('Underdog', () => { srv.stop(done); }); - request.on('push', () => new Error('Should not make it here')); + request.on('push', () => done(new Error('Should not make it here'))); }); }); @@ -531,7 +531,7 @@ describe('Underdog', () => { srv.stop(done); }); - request.on('push', () => new Error('Should not make it here')); + request.on('push', () => done(new Error('Should not make it here'))); }); });