Skip to content

Commit

Permalink
Support hapi v18. Closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jan 20, 2019
1 parent fd936f6 commit 8021cdd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js

node_js:
- "8"
- "9"
- "10"
- "node"

after_script: "npm run coveralls"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ Lead Maintainer - [Devin Ivy](https://github.com/devinivy)

## Usage
> See also the [API Reference](API.md)
>
> If you would like to utilize underdog with hapi v17, please use underdog v2.
Underdog brings [HTTP/2 server-push](http://httpwg.org/specs/rfc7540.html#PushResources) to **hapi v17+**. The way it works is that you specify paths to resources that you'd like to push alongside a particular response. This is achieved with a call to the response toolkit decoration [`h.push()`](API.md#hpushresponse-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!
Underdog brings [HTTP/2 server-push](http://httpwg.org/specs/rfc7540.html#PushResources) to **hapi v18+**. The way it works is that you specify paths to resources that you'd like to push alongside a particular response. This is achieved with a call to the response toolkit decoration [`h.push()`](API.md#hpushresponse-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
```js
Expand Down
14 changes: 10 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module.exports = {

server.decorate('toolkit', 'push', function (response, paths, headers) {

if (typeof response === 'string' || Array.isArray(response)) {
Hoek.assert(response, 'Must provide a path to the resource to be pushed.');

if (typeof response !== 'object') {
headers = paths;
paths = response;
response = this.request.response;
Expand Down Expand Up @@ -97,15 +99,19 @@ module.exports = {
method: 'get', // The head method is allowed, but perhaps not practical
url: push.path,
headers: Hoek.applyToDefaults(userAgent, push.headers),
credentials: request.auth.credentials,
auth: !request.auth.isAuthenticated ? undefined : {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts,
strategy: request.auth.strategy
},
plugins: { underdog: { req, res, pushing: true } },
allowInternals: true
});

// Remove deprecated headers

const reqHeaders = Hoek.shallow(pushResponse.raw.req.headers);
const resHeaders = Hoek.shallow(pushResponse.headers);
const reqHeaders = Object.assign({}, pushResponse.raw.req.headers);
const resHeaders = Object.assign({}, pushResponse.headers);

for (let i = 0; i < internals.deprecatedHeaders.length; ++i) {
const deprecated = internals.deprecatedHeaders[i];
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
},
"homepage": "https://github.com/hapipal/underdog#readme",
"dependencies": {
"hoek": "5.x.x"
"hoek": "6.x.x"
},
"peerDependencies": {
"hapi": ">=17 <18"
"hapi": ">=18 <19"
},
"devDependencies": {
"boom": "5.x.x",
"boom": "7.x.x",
"code": "5.x.x",
"coveralls": "3.x.x",
"hapi": "17.x.x",
"lab": ">=15.2.0 <16",
"hapi": "18.x.x",
"lab": "18.x.x",
"toys": ">=2.1.1 <3"
}
}

0 comments on commit 8021cdd

Please sign in to comment.