hapi Etag helper plugin
3.x- last version compatible with hapi 16
>=4- latest hapi
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:
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.
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.