From ebd93c8d57991c91d0844996e690d670bba7178f Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Thu, 20 Oct 2022 10:47:27 +0200 Subject: LibWeb: Revert support for DOM::Document in XHR::send() This is a manual revert of commit: 7831e62 Let's revert this until we got nested union support in our IDL generator/parser. --- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 29 +++++++----------------- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h | 2 +- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl | 3 +-- 3 files changed, 10 insertions(+), 24 deletions(-) (limited to 'Userland/Libraries') 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 XMLHttpRequest::open(String const& method_string, Stri } // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send -WebIDL::ExceptionOr XMLHttpRequest::send(Optional, Fetch::XMLHttpRequestBodyInit>> body) +WebIDL::ExceptionOr XMLHttpRequest::send(Optional body) { auto& vm = this->vm(); auto& realm = *vm.current_realm(); @@ -411,15 +411,8 @@ WebIDL::ExceptionOr XMLHttpRequest::send(Optional body_with_type {}; - Optional serialized_document {}; - if (body.has_value()) { - if (body->has>()) { - serialized_document = body->get>().cell()->serialize_fragment().to_byte_buffer(); - } else { - body_with_type = TRY(Fetch::extract_body(realm, body.value().get())); - } - } + auto body_with_type = body.has_value() ? TRY(Fetch::extract_body(realm, body.value())) : Optional {}; + 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 XMLHttpRequest::send(Optionalpage()); 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 { auto byte_buffer = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(buffer)); @@ -456,14 +447,10 @@ WebIDL::ExceptionOr XMLHttpRequest::send(Optional WebIDL::ExceptionOr { 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>()) { - 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) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index 574ac27a61..77037dc230 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -47,7 +47,7 @@ public: WebIDL::ExceptionOr open(String const& method, String const& url); WebIDL::ExceptionOr open(String const& method, String const& url, bool async, String const& username = {}, String const& password = {}); - WebIDL::ExceptionOr send(Optional, Fetch::XMLHttpRequestBodyInit>> body = {}); + WebIDL::ExceptionOr send(Optional body); WebIDL::ExceptionOr set_request_header(String const& header, String const& value); void set_response_type(Bindings::XMLHttpRequestResponseType type) { m_response_type = type; } diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl index a0943b18ba..ca967466a9 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl @@ -1,4 +1,3 @@ -#import #import #import #import @@ -34,7 +33,7 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget { undefined open(DOMString method, DOMString url); undefined open(ByteString method, USVString url, boolean async, optional USVString? username = {}, optional USVString? password = {}); undefined setRequestHeader(DOMString name, DOMString value); - undefined send(optional (Document or XMLHttpRequestBodyInit)? body = null); + undefined send(optional XMLHttpRequestBodyInit? body = null); ByteString? getResponseHeader(ByteString name); ByteString getAllResponseHeaders(); -- cgit v1.2.3