mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
LibWeb: Add support for Blob to XHR::send()
This commit is contained in:
parent
9b3da5a142
commit
0a511e29d1
3 changed files with 15 additions and 3 deletions
|
@ -326,8 +326,18 @@ static Fetch::BodyWithType extract_body(XMLHttpRequestBodyInit const& body_init)
|
||||||
Optional<ByteBuffer> type {};
|
Optional<ByteBuffer> type {};
|
||||||
|
|
||||||
// 6. Switch on object.
|
// 6. Switch on object.
|
||||||
// FIXME: Still need to support Blob, BufferSource and FormData
|
// FIXME: Still need to support BufferSource and FormData
|
||||||
body_init.visit(
|
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 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<URL::URLSearchParams> const& url_search_params) {
|
[&](NonnullRefPtr<URL::URLSearchParams> const& url_search_params) {
|
||||||
// Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list.
|
// 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();
|
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()) {
|
if (body_with_type.has_value()) {
|
||||||
body_with_type->body.source().visit(
|
body_with_type->body.source().visit(
|
||||||
[&](ByteBuffer const& buffer) { request.set_body(buffer); },
|
[&](ByteBuffer const& buffer) { request.set_body(buffer); },
|
||||||
|
[&](NonnullRefPtr<FileAPI::Blob> const& blob) { request.set_body(blob->m_byte_buffer); },
|
||||||
[](auto&) {});
|
[](auto&) {});
|
||||||
if (body_with_type->type.has_value())
|
if (body_with_type->type.has_value())
|
||||||
request.set_header("Content-Type", String { body_with_type->type->span() });
|
request.set_header("Content-Type", String { body_with_type->type->span() });
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
namespace Web::XHR {
|
namespace Web::XHR {
|
||||||
|
|
||||||
using XMLHttpRequestBodyInit = Variant<NonnullRefPtr<URL::URLSearchParams>, String>;
|
using XMLHttpRequestBodyInit = Variant<NonnullRefPtr<FileAPI::Blob>, NonnullRefPtr<URL::URLSearchParams>, String>;
|
||||||
|
|
||||||
class XMLHttpRequest final
|
class XMLHttpRequest final
|
||||||
: public RefCounted<XMLHttpRequest>
|
: public RefCounted<XMLHttpRequest>
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#import <XHR/XMLHttpRequestEventTarget.idl>
|
#import <XHR/XMLHttpRequestEventTarget.idl>
|
||||||
#import <DOM/EventHandler.idl>
|
#import <DOM/EventHandler.idl>
|
||||||
|
#import <FileAPI/Blob.idl>
|
||||||
#import <URL/URLSearchParams.idl>
|
#import <URL/URLSearchParams.idl>
|
||||||
|
|
||||||
typedef (URLSearchParams or USVString) XMLHttpRequestBodyInit;
|
typedef (Blob or URLSearchParams or USVString) XMLHttpRequestBodyInit;
|
||||||
|
|
||||||
enum XMLHttpRequestResponseType {
|
enum XMLHttpRequestResponseType {
|
||||||
"",
|
"",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue