From 5ed1fe40c6640a01bdde55a21b473d1b076e9114 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:57:05 -0500 Subject: [PATCH] fix: ky headers option --- .../base/http-clients/ky-http-client.ejs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/templates/base/http-clients/ky-http-client.ejs b/templates/base/http-clients/ky-http-client.ejs index 87d73093..26fcabfa 100644 --- a/templates/base/http-clients/ky-http-client.ejs +++ b/templates/base/http-clients/ky-http-client.ejs @@ -99,14 +99,24 @@ export class HttpClient { } } + let headers: Headers | Record | undefined; + if (options.headers instanceof Headers) { + headers = new Headers(options.headers); + if (type && type !== ContentType.FormData) { + headers.set('Content-Type', type); + } + } else { + headers = { ...options.headers } as Record; + if (type && type !== ContentType.FormData) { + headers['Content-Type'] = type; + } + } + const request = this.ky(path, { - ...options, - headers: { - ...(options.headers || {}), - ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), - }, - searchParams: query, - body: body as any, + ...options, + headers, + searchParams: query, + body: body as any, }); <% if (config.unwrapResponseData) { %>