diff --git a/source/plugins/etag-plugin/index.js b/source/plugins/etag-plugin/index.js new file mode 100644 index 0000000..eaf85a6 --- /dev/null +++ b/source/plugins/etag-plugin/index.js @@ -0,0 +1,19 @@ +const etag = require("etag") + +const plugin = { + name: "etagPlugin", + version: "1.0.0", + register: (server, options) => { + server.ext("onPreResponse", (request, h) => { + const response = request.response + if (response.isBoom || !response.is("application/json")) { + return h.continue + } + const etagValue = etag(response.source) + response.etag(etagValue) + return h.continue + }) + }, +} + +module.exports = plugin