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) { %>