mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 07:20:02 -04:00
fix link header rewriter
This commit is contained in:
parent
bac00de12b
commit
58a1f6fbb2
1 changed files with 12 additions and 5 deletions
|
@ -24,6 +24,11 @@ const cspHeaders = [
|
||||||
|
|
||||||
const urlHeaders = ["location", "content-location", "referer"];
|
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) {
|
export function rewriteHeaders(rawHeaders: BareHeaders, origin?: URL) {
|
||||||
const headers = {};
|
const headers = {};
|
||||||
|
|
||||||
|
@ -43,11 +48,13 @@ export function rewriteHeaders(rawHeaders: BareHeaders, origin?: URL) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// if (headers["link"]) {
|
if (typeof headers["link"] === "string") {
|
||||||
// headers["link"] = headers["link"].replace(/<(.*?)>/gi, (match) =>
|
headers["link"] = rewriteLinkHeader(headers["link"], origin)
|
||||||
// encodeUrl(match, origin)
|
} else if (Array.isArray(headers["link"])) {
|
||||||
// );
|
headers["link"] = headers["link"].map((link) =>
|
||||||
// }
|
rewriteLinkHeader(link, origin)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue