Skip to content

Commit

Permalink
fix: ky headers option
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Mar 5, 2024
1 parent 66c617d commit 3d7ae28
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions templates/base/http-clients/ky-http-client.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,24 @@ export class HttpClient<SecurityDataType = unknown> {
}
}

let headers: Headers | Record<string, string> | 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<string, string>;
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) { %>
Expand Down

0 comments on commit 3d7ae28

Please sign in to comment.