Made .redirect() respect the provided options

This commit is contained in:
Kir_Antipov 2024-01-04 11:04:38 +00:00
parent 78c153f935
commit 577191382f

View file

@ -173,7 +173,18 @@ export class HttpResponse {
* @returns The newly created {@link HttpResponse} instance. * @returns The newly created {@link HttpResponse} instance.
*/ */
static redirect(url: string | URL, options?: HttpResponseOptions): HttpResponse { 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;
} }
/** /**