From ea37472e7744b6d7aac7914af85b57d3c2e46261 Mon Sep 17 00:00:00 2001 From: Gabi Villalonga Simon Date: Wed, 20 Nov 2024 14:50:00 -0600 Subject: [PATCH] fix: do not add query params on top of the URL with query params --- src/router.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/router.ts b/src/router.ts index 0a92340..6606f26 100644 --- a/src/router.ts +++ b/src/router.ts @@ -84,11 +84,13 @@ v2Router.delete("/:name+/manifests/:reference", async (req, env: Env) => { } } + const url = new URL(req.url); if (tags.truncated) { + url.searchParams.set("last", tags.truncated ? tags.cursor : ""); return new Response(JSON.stringify(ManifestTagsListTooBigError), { status: 400, headers: { - "Link": `${req.url}/?last=${tags.truncated ? tags.cursor : ""}; rel=next`, + "Link": `${url.toString()}; rel=next`, "Content-Type": "application/json", }, }); @@ -529,6 +531,9 @@ v2Router.get("/:name+/tags/list", async (req, env: Env) => { }); const keys = tags.objects.map((object) => object.key.split("/").pop()!); + const url = new URL(req.url); + url.searchParams.set("n", `${n}`); + url.searchParams.set("last", keys.length ? keys[keys.length - 1] : ""); return new Response( JSON.stringify({ name, @@ -538,7 +543,7 @@ v2Router.get("/:name+/tags/list", async (req, env: Env) => { status: 200, headers: { "Content-Type": "application/json", - "Link": `${req.url}?n=${n}&last=${keys.length ? keys[keys.length - 1] : ""}; rel=next`, + "Link": `${url.toString()}; rel=next`, }, }, );