6.0.0 • Published 4 years ago

etagger v6.0.0

Weekly downloads
71
License
MIT
Repository
github
Last release
4 years ago

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

6.0.0

4 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

7 years ago

5.0.0

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.1-2

7 years ago

2.0.1-1

7 years ago

2.0.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago