Skip to content

Commit 5ed1fe4

Browse files
committedMar 5, 2024
fix: ky headers option
1 parent 66c617d commit 5ed1fe4

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed
 

‎templates/base/http-clients/ky-http-client.ejs

+17-7
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,24 @@ export class HttpClient<SecurityDataType = unknown> {
9999
}
100100
}
101101

102+
let headers: Headers | Record<string, string | undefined> | undefined;
103+
if (options.headers instanceof Headers) {
104+
headers = new Headers(options.headers);
105+
if (type && type !== ContentType.FormData) {
106+
headers.set('Content-Type', type);
107+
}
108+
} else {
109+
headers = { ...options.headers } as Record<string, string | undefined>;
110+
if (type && type !== ContentType.FormData) {
111+
headers['Content-Type'] = type;
112+
}
113+
}
114+
102115
const request = this.ky(path, {
103-
...options,
104-
headers: {
105-
...(options.headers || {}),
106-
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
107-
},
108-
searchParams: query,
109-
body: body as any,
116+
...options,
117+
headers,
118+
searchParams: query,
119+
body: body as any,
110120
});
111121

112122
<% if (config.unwrapResponseData) { %>

0 commit comments

Comments
 (0)
Please sign in to comment.