fix link header rewriter

This commit is contained in:
Avad3 2024-08-11 11:46:25 -04:00
parent bac00de12b
commit 58a1f6fbb2

View file

@ -24,6 +24,11 @@ const cspHeaders = [
const urlHeaders = ["location", "content-location", "referer"];
function rewriteLinkHeader(link: string, origin?: URL) {
return link
.replace(/<(.*)>/gi, (match) => encodeUrl(match, origin));
}
export function rewriteHeaders(rawHeaders: BareHeaders, origin?: URL) {
const headers = {};
@ -43,11 +48,13 @@ export function rewriteHeaders(rawHeaders: BareHeaders, origin?: URL) {
);
});
// if (headers["link"]) {
// headers["link"] = headers["link"].replace(/<(.*?)>/gi, (match) =>
// encodeUrl(match, origin)
// );
// }
if (typeof headers["link"] === "string") {
headers["link"] = rewriteLinkHeader(headers["link"], origin)
} else if (Array.isArray(headers["link"])) {
headers["link"] = headers["link"].map((link) =>
rewriteLinkHeader(link, origin)
);
}
return headers;
}