rjweb-server
Version:
Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS
18 lines (17 loc) • 641 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = require("crypto");
/**
* Generate a Hash from a Body, Headers & Status Code to be used for caching using SHA1
* @since 6.0.0
*/ function toETag(data, headers, cookies, status) {
if (status < 200 || status >= 400)
return null;
const hashed = (0, crypto_1.createHash)('sha1')
.update(JSON.stringify(headers))
.update(JSON.stringify(Object.values(cookies).map((v) => v.value)))
.update(Buffer.from(data))
.digest('hex');
return `W/"${status.toString(16)}-${hashed}"`;
}
exports.default = toETag;