From 3d7ae2830cc4c7f75eddf2915210045332a22e68 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..9aa88ae9 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) { %>