Nitrate Processed Mincemeat
Have ideas to improve npm?Join in the discussion! »

etagger
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

etagger

hapi Etag helper plugin

npm Build Status Coverage Status Dependency Status devDependency Status node

Versions

  • 3.x - last version compatible with hapi 16
  • >=4 - latest hapi

Usage

await server.register(
  {
    plugin: require('etagger'),
    options: pluginOptions
  },
  options
)

Options

  • enabled: Boolean - Enable processing for the connection/the current route. (Default: undefined - not enabled by default.)
  • nonSuccess: Boolean - Enable processing for non-success (not 2xx) status codes. (Default: undefined)

For string and buffer response sources, the ETag will simply be attached.

Stream and error response sources are ignored.

These options can either be set in the plugin options (see above) or per-route:

{
  "config": {
    "plugins": {
      "etagger": {
        /* ... */
      }
    }
  }
}

When set in the route, these options will override the plugin options.

server.plugins.etagger.etag(response, opts)

Manually attach an ETag to a response. This is useful i.e. to etag manually in your own extension handlers.

  • response - The response object.
  • opts - Same as the options.
    • enabled - Ignored. This function will always attach an ETag to the response.

No stream support

If you want to attach an ETag to a resource, just give up on streaming it. ETag is based on the value of the whole resource, so there's no point to attaching an ETag to it if we might not have all of it.

Alternatively, precalculate the ETag that you want to attach to a resource. That way you can just call response.etag() when you stream it. 👍

You can also try buffering the whole resource, in which case, you can just submit the resulting buffer to reply and be able to use this plugin.

Streaming is awesome, but there are situations where it is right or it is wrong to use with.

License

MIT

Keywords

Install

npm i etagger

DownloadsWeekly Downloads

42

Version

6.0.0

License

MIT

Unpacked Size

12.3 kB

Total Files

7

Last publish

Collaborators

  • avatar