1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:38:10 +00:00

LibWeb: Add support for Blob to XHR::send()

This commit is contained in:
Kenneth Myhra 2022-07-18 15:15:53 +02:00 committed by Linus Groh
parent 9b3da5a142
commit 0a511e29d1
3 changed files with 15 additions and 3 deletions

View file

@ -326,8 +326,18 @@ static Fetch::BodyWithType extract_body(XMLHttpRequestBodyInit const& body_init)
Optional<ByteBuffer> 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<FileAPI::Blob> const& blob) {
// FIXME: Set action to this step: read object.
// Set source to object.
source = blob;
// Set length to objects size.
length = blob->size();
// If objects 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<URL::URLSearchParams> const& url_search_params) {
// Set source to the result of running the application/x-www-form-urlencoded serializer with objects list.
source = url_search_params->to_string().to_byte_buffer();
@ -514,6 +524,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<XMLHttpRequestBodyInit> bod
if (body_with_type.has_value()) {
body_with_type->body.source().visit(
[&](ByteBuffer const& buffer) { request.set_body(buffer); },
[&](NonnullRefPtr<FileAPI::Blob> 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() });