Never set multipart/form-data manually, kids

Why did I do this?
This commit is contained in:
Kir_Antipov 2024-01-04 10:42:05 +00:00
parent 814b583fb0
commit 78c153f935

View file

@ -134,7 +134,8 @@ export class HttpResponse {
* @returns The newly created {@link HttpResponse} instance. * @returns The newly created {@link HttpResponse} instance.
*/ */
static formData(formData: FormData, options?: HttpResponseOptions): HttpResponse { 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. * @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); ArgumentNullError.throwIfNull(data);
const headers = new NodeFetchHeaders(options?.headers); const headers = new NodeFetchHeaders(options?.headers);
if (!headers.has("Content-Type")) { if (contentType && !headers.has("Content-Type")) {
headers.set("Content-Type", contentType); headers.set("Content-Type", contentType);
} }