seangenabe / etagger

hapi ETag helper plugin
MIT License
2 stars 1 forks source link
etag hapi hapi-plugin

etagger

hapi Etag helper plugin

npm Build Status Coverage Status Dependency Status devDependency Status node

Versions

Usage

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

Options

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.

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