UNPKG

rjweb-server

Version:

Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS

11 lines (10 loc) 383 B
import { createHash } from "crypto"; function toETag(data, headers, cookies, status) { if (status < 200 || status >= 300) return null; const hashed = createHash("sha1").update(JSON.stringify(headers)).update(JSON.stringify(Object.values(cookies).map((v) => v.value))).update(data).digest("hex"); return `${status.toString(16)}-${hashed}`; } export { toETag as default };