diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index adb8d7d202..8e972779bb 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -326,8 +326,18 @@ static Fetch::BodyWithType extract_body(XMLHttpRequestBodyInit const& body_init) Optional type {}; // 6. Switch on object. - // FIXME: Still need to support Blob, BufferSource and FormData + // FIXME: Still need to support BufferSource and FormData body_init.visit( + [&](NonnullRefPtr const& blob) { + // FIXME: Set action to this step: read object. + // Set source to object. + source = blob; + // Set length to object’s size. + length = blob->size(); + // If object’s type attribute is not the empty byte sequence, set type to its value. + if (!blob->type().is_empty()) + type = blob->type().to_byte_buffer(); + }, [&](NonnullRefPtr const& url_search_params) { // Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list. source = url_search_params->to_string().to_byte_buffer(); @@ -514,6 +524,7 @@ DOM::ExceptionOr XMLHttpRequest::send(Optional bod if (body_with_type.has_value()) { body_with_type->body.source().visit( [&](ByteBuffer const& buffer) { request.set_body(buffer); }, + [&](NonnullRefPtr const& blob) { request.set_body(blob->m_byte_buffer); }, [](auto&) {}); if (body_with_type->type.has_value()) request.set_header("Content-Type", String { body_with_type->type->span() }); diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index 83309d2a00..1429860661 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -23,7 +23,7 @@ namespace Web::XHR { -using XMLHttpRequestBodyInit = Variant, String>; +using XMLHttpRequestBodyInit = Variant, NonnullRefPtr, String>; class XMLHttpRequest final : public RefCounted diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl index c712fd9aa2..874006ea25 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl @@ -1,8 +1,9 @@ #import #import +#import #import -typedef (URLSearchParams or USVString) XMLHttpRequestBodyInit; +typedef (Blob or URLSearchParams or USVString) XMLHttpRequestBodyInit; enum XMLHttpRequestResponseType { "",