From 577191382f5ac47761c752f065c9530ec5e0678f Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Thu, 4 Jan 2024 11:04:38 +0000 Subject: [PATCH] Made `.redirect()` respect the provided options --- src/utils/net/http-response.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/net/http-response.ts b/src/utils/net/http-response.ts index 4330862..8286ebf 100644 --- a/src/utils/net/http-response.ts +++ b/src/utils/net/http-response.ts @@ -173,7 +173,18 @@ export class HttpResponse { * @returns The newly created {@link HttpResponse} instance. */ static redirect(url: string | URL, options?: HttpResponseOptions): HttpResponse { - return Response.redirect(asString(url), options?.status) as NodeFetchResponse; + const headers = new NodeFetchHeaders(options?.headers); + if (!headers.has("Location")) { + headers.set("Location", asString(url)); + } + + const redirectOptions = { + headers, + status: options.status ?? 302, + statusText: options.statusText ?? "Found", + } as HttpResponseOptions; + + return new Response("", redirectOptions) as NodeFetchResponse; } /**