Skip to content

Latest commit

 

History

History
18 lines (13 loc) · 2.4 KB

API.md

File metadata and controls

18 lines (13 loc) · 2.4 KB

API

Underdog

The hapi 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, which means hapi will ensure it is not registered multiple times.

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().

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

  • response - the hapi response 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 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.

Returns an object { response, allowed } where response is the response for which resources are intended to be pushed, and allowed indicates whether the server-push was allowed by the client and protocol (when false, no resources were pushed).

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 and HTTP/2 Session Settings in the nodejs docs for more info.