Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps and instructions for hapi v.16 scrub #7

Merged
merged 4 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
package-lock.json
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ language: node_js
node_js:
- "4"
- "6"
- "8.7.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this version exactly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh totally missed your commit message, sorry! Wow!! I would definitely have expected that to be a semver major!

nodejs/node#15685

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:trollface: oh man, yea. took me a bit to peek through their changelog to sort that out. 🎺


after_script: "npm run coveralls"
18 changes: 18 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -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`
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"hapi": ">=10 <16"
},
"devDependencies": {
"boom": "4.x.x",
"code": "3.x.x",
"coveralls": "2.x.x",
"boom": "5.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"
}
}
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ describe('Underdog', () => {
srv.stop(done);
});

request.on('push', () => next(new Error('Should not make it here')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning an error wont do anything! You'd have to at least throw it. I think that next was possibly supposed to be done.

Copy link
Member Author

@zemccartney zemccartney Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ay, gotcha. thanks for pointing that out. slopslopslop. fixing now!

request.on('push', () => done(new Error('Should not make it here')));
});
});

Expand Down Expand Up @@ -531,7 +531,7 @@ describe('Underdog', () => {
srv.stop(done);
});

request.on('push', () => next(new Error('Should not make it here')));
request.on('push', () => done(new Error('Should not make it here')));
});
});

Expand Down