Skip to content

Commit 9b4bb64

Browse files
authored
Delete explicit Content-Type for FormData input (#268)
* Delete explicit Content-Type for FormData input * Update tests
1 parent 0d7a60b commit 9b4bb64

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ class Replicate {
220220
url.searchParams.append(key, value);
221221
}
222222

223-
const headers = {};
223+
const headers = {
224+
"Content-Type": "application/json",
225+
"User-Agent": userAgent,
226+
};
224227
if (auth) {
225228
headers["Authorization"] = `Bearer ${auth}`;
226229
}
227-
headers["Content-Type"] = "application/json";
228-
headers["User-Agent"] = userAgent;
229230
if (options.headers) {
230231
for (const [key, value] of Object.entries(options.headers)) {
231232
headers[key] = value;
@@ -235,6 +236,8 @@ class Replicate {
235236
let body = undefined;
236237
if (data instanceof FormData) {
237238
body = data;
239+
// biome-ignore lint/performance/noDelete:
240+
delete headers["Content-Type"]; // Use automatic content type header
238241
} else if (data) {
239242
body = JSON.stringify(data);
240243
}

index.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ describe("Replicate client", () => {
296296

297297
nock(BASE_URL)
298298
.post("/files")
299-
.matchHeader("Content-Type", "multipart/form-data")
300299
.reply(201, {
301300
urls: {
302301
get: "https://replicate.com/api/files/123",
@@ -317,17 +316,14 @@ describe("Replicate client", () => {
317316
prompt: "Tell me a story",
318317
data,
319318
},
320-
stream: true,
321319
});
322320

323321
expect(client.fetch).toHaveBeenCalledWith(
324322
new URL("https://api.replicate.com/v1/files"),
325323
{
326324
method: "POST",
327325
body: expect.any(FormData),
328-
headers: expect.objectContaining({
329-
"Content-Type": "multipart/form-data",
330-
}),
326+
headers: expect.any(Object),
331327
}
332328
);
333329
const form = mockedFetch.mock.calls[0][1]?.body as FormData;

0 commit comments

Comments
 (0)