Skip to content

Commit

Permalink
Merge branch 'master' into node-core-http2
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jan 8, 2018
2 parents 6f3d6fb + 82c9b36 commit be4e575
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 0 additions & 2 deletions API.md
Expand Up @@ -6,7 +6,6 @@ You should register Underdog in any plugin that would like to take advantage of
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()`](https://github.com/hapijs/hapi/blob/master/API.md#server.ext()).

#### `h.push([response], path, [headers])`

- `response` - the hapi [response](https://github.com/hapijs/hapi/blob/master/API.md#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](https://github.com/hapijs/hapi/blob/master/API.md#server.realm) 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.
Expand All @@ -16,5 +15,4 @@ Note, Underdog utilizes an `onPreResponse` extension to finalize server-push, so
Note that when push requests are resolved credentials from the originating request will be used, and that routes marked as `isInternal` are accessible.

#### `h.pushAllowed()`

Returns `true` or `false`, indicating whether server-push is allowed by the client and protocol. Sometimes resources cannot be pushed, for example when the server handles an http/1.1 request or when an http/2 client disables pushes. See [ALPN Negotiation](https://nodejs.org/api/http2.html#http2_alpn_negotiation) and [HTTP/2 Session Settings](https://nodejs.org/api/http2.html#http2_settings_object) in the nodejs docs for more info.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -3,7 +3,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 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
Expand Down

0 comments on commit be4e575

Please sign in to comment.