From 78c153f935cadbf8368536a808a650d6cc35ccde Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Thu, 4 Jan 2024 10:42:05 +0000 Subject: [PATCH] Never set `multipart/form-data` manually, kids Why did I do this? --- src/utils/net/http-response.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/net/http-response.ts b/src/utils/net/http-response.ts index 2c31ed0..4330862 100644 --- a/src/utils/net/http-response.ts +++ b/src/utils/net/http-response.ts @@ -134,7 +134,8 @@ export class HttpResponse { * @returns The newly created {@link HttpResponse} instance. */ static formData(formData: FormData, options?: HttpResponseOptions): HttpResponse { - return HttpResponse.content(formData, "multipart/form-data", options); + // Response constructor will automatically set the "Content-Type" header. + return HttpResponse.content(formData, undefined, options); } /** @@ -193,11 +194,11 @@ export class HttpResponse { * * @returns The newly created {@link HttpResponse} instance. */ - private static content(data: string | FormData | Blob, contentType: string, options?: HttpResponseOptions): HttpResponse { + private static content(data: string | FormData | Blob, contentType?: string, options?: HttpResponseOptions): HttpResponse { ArgumentNullError.throwIfNull(data); const headers = new NodeFetchHeaders(options?.headers); - if (!headers.has("Content-Type")) { + if (contentType && !headers.has("Content-Type")) { headers.set("Content-Type", contentType); }