diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-18 12:23:02 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-18 12:53:06 +0200 |
commit | 0ca1b4b123e38417eb21a9d88010c6f4705224e8 (patch) | |
tree | 6047ef112808815141c3957f71df20ca2ade0fb3 | |
parent | 575e3bf37dc66023c0fb47b93ca3104c85bae683 (diff) | |
download | serenity-0ca1b4b123e38417eb21a9d88010c6f4705224e8.zip |
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.
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 7 |
1 files 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<void> XMLHttpRequest::send(Optional<XMLHttpRequestBodyInit> bod auto byte_buffer = TRY(ByteBuffer::copy(blob->bytes())); request.set_body(byte_buffer); return {}; }, [](auto&) -> ErrorOr<void> { 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); |