From 3295ed17ea36988890db8c162b86c158f54918c3 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Tue, 28 Jan 2025 19:05:25 +0000 Subject: [PATCH] LibWeb: Use application/octet-stream for unknown FormData file types Required by web.whatsapp.com, which uses fetch() to send FormData bodies containing Files with empty types. Ref https://github.com/LadybirdBrowser/ladybird/issues/2941 --- Libraries/LibWeb/HTML/FormControlInfrastructure.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp index 9a80d793c2f..ea6b45c81da 100644 --- a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp +++ b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp @@ -278,7 +278,13 @@ ErrorOr serialize_to_multipart_form_data(Vectortype())))); + // RFC7578: If the contents of a file are to be sent, the file data SHOULD be labeled with an appropriate media type, if known, or + // "application/octet-stream". + if (!file->type().is_empty()) { + TRY(builder.try_append(TRY(String::formatted("Content-Type: {}\r\n\r\n", file->type())))); + } else { + TRY(builder.try_append("Content-Type: application/octet-stream\r\n\r\n"sv)); + } TRY(builder.try_append(file->raw_bytes())); TRY(builder.try_append("\r\n"sv)); return {};