From 0ca1b4b123e38417eb21a9d88010c6f4705224e8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 18 Sep 2022 12:23:02 +0200 Subject: [PATCH] LibWeb: Don't replace existing Content-Type header in outgoing XHRs This fixes an issue where Twitter was HTTP 400'ing some of our XHRs. --- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 2772d7b7ce..0996a42101 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -493,8 +493,11 @@ DOM::ExceptionOr XMLHttpRequest::send(Optional bod auto byte_buffer = TRY(ByteBuffer::copy(blob->bytes())); request.set_body(byte_buffer); return {}; }, [](auto&) -> ErrorOr { return {}; })); - if (body_with_type->type.has_value()) - request.set_header("Content-Type", String { body_with_type->type->span() }); + if (body_with_type->type.has_value()) { + // If type is non-null and this’s headers’s header list does not contain `Content-Type`, then append (`Content-Type`, type) to this’s headers. + if (!m_request_headers.contains("Content-Type"sv)) + request.set_header("Content-Type", String { body_with_type->type->span() }); + } } for (auto& it : m_request_headers) request.set_header(it.key, it.value);