mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -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"];
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue