UNPKG

@worker-tools/middleware

Version:

A suite of standalone HTTP server middlewares for Worker Runtimes.

14 lines 704 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.caching = void 0; const cache_control_1 = require("@tusbar/cache-control"); const SECOND = { unit: 'second', relativeTo: '1970-01-01' }; const isDuration = (x) => (x === null || x === void 0 ? void 0 : x[Symbol.toStringTag]) === 'Temporal.Duration'; const caching = (options = {}) => async (ax) => { const x = await ax; const opts = Object.fromEntries(Object.entries(options).map(([k, v]) => [k, isDuration(v) ? v.total(SECOND) : v])); x.effects.push(res => res.headers.set('Cache-Control', (0, cache_control_1.format)(opts))); return x; }; exports.caching = caching; //# sourceMappingURL=caching.js.map