1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { fetch } from "https://esm.town/v/std/fetch";
export async function csp(url) {
const response = await fetch(url);
const policies = response.headers.get("Content-Security-Policy").split(";")
.map((p) => p.trim()).filter(String);
return policies.reduce((acc, el) => {
const spaceIndex = el.indexOf(" ");
const directive = el.slice(0, spaceIndex);
const values = el.slice(spaceIndex + 1, el.length);
acc[directive] = values.split(" ");
return acc;
}, {});
}