1 changed files with 19 additions and 0 deletions
@ -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 |
Loading…
Reference in new issue