UNPKG

tezx

Version:

TezX is a modern, ultra-lightweight, and high-performance JavaScript framework built specifically for Bun. It provides a minimal yet powerful API, seamless environment management, and a high-concurrency HTTP engine for building fast, scalable web applicat

19 lines (18 loc) 719 B
const sanitizeHeaders = (options = {}) => { const { whitelist = [], blacklist = [] } = options; const normalizedWhitelist = whitelist.map((h) => h.toLowerCase()); const normalizedBlacklist = blacklist.map((h) => h.toLowerCase()); let lWhite = normalizedWhitelist.length; return async function sanitizeHeaders(ctx, next) { await next(); for (const key of ctx.headers.keys()) { if (lWhite > 0 && !normalizedWhitelist.includes(key)) { ctx.headers.delete(key); } if (normalizedBlacklist.includes(key)) { ctx.headers.delete(key); } } }; }; export { sanitizeHeaders as default, sanitizeHeaders };