summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp')
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp29
1 files changed, 8 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
index 8244360fd2..a8c9e62eea 100644
--- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
+++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
@@ -396,7 +396,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
}
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send
-WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Variant<JS::Handle<DOM::Document>, Fetch::XMLHttpRequestBodyInit>> body)
+WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBodyInit> body)
{
auto& vm = this->vm();
auto& realm = *vm.current_realm();
@@ -411,15 +411,8 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Variant<JS::Handle<DOM::
if (m_method.is_one_of("GET"sv, "HEAD"sv))
body = {};
- Optional<Fetch::Infrastructure::BodyWithType> body_with_type {};
- Optional<ByteBuffer> serialized_document {};
- if (body.has_value()) {
- if (body->has<JS::Handle<DOM::Document>>()) {
- serialized_document = body->get<JS::Handle<DOM::Document>>().cell()->serialize_fragment().to_byte_buffer();
- } else {
- body_with_type = TRY(Fetch::extract_body(realm, body.value().get<Fetch::XMLHttpRequestBodyInit>()));
- }
- }
+ auto body_with_type = body.has_value() ? TRY(Fetch::extract_body(realm, body.value())) : Optional<Fetch::Infrastructure::BodyWithType> {};
+
AK::URL request_url = m_window->associated_document().parse_url(m_url.to_string());
dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url);
@@ -439,9 +432,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Variant<JS::Handle<DOM::
auto request = LoadRequest::create_for_url_on_page(request_url, m_window->page());
request.set_method(m_method);
- if (serialized_document.has_value()) {
- request.set_body(serialized_document.release_value());
- } else if (body_with_type.has_value()) {
+ if (body_with_type.has_value()) {
TRY(body_with_type->body.source().visit(
[&](ByteBuffer const& buffer) -> WebIDL::ExceptionOr<void> {
auto byte_buffer = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(buffer));
@@ -456,14 +447,10 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Variant<JS::Handle<DOM::
[](auto&) -> WebIDL::ExceptionOr<void> {
return {};
}));
- }
-
- // 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)) {
- if (body_with_type.has_value() && body_with_type->type.has_value()) {
- request.set_header("Content-Type", String { body_with_type->type->span() });
- } else if (body.has_value() && body->has<JS::Handle<DOM::Document>>()) {
- request.set_header("Content-Type", "text/html;charset=UTF-8");
+ 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)