mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:48:14 +00:00
LibWeb: Add public get accessor function for Blob's internal ByteBuffer
Blob::bytes() returns the ReadonlyBytes representation of our internal ByteBuffer. This change requires us to ByteBuffer::copy() Blob's ReadonlyBytes to a ByteBuffer in XHR::send() and corresponding error handling of the copy operation. This removes the need for Blob to declare XMLHttpRequest as a friend class.
This commit is contained in:
parent
417a385db1
commit
622a4f29a7
3 changed files with 16 additions and 7 deletions
|
@ -475,10 +475,19 @@ DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<XMLHttpRequestBodyInit> bod
|
|||
auto request = LoadRequest::create_for_url_on_page(request_url, m_window->page());
|
||||
request.set_method(m_method);
|
||||
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&) {});
|
||||
TRY_OR_RETURN_OOM(body_with_type->body.source().visit(
|
||||
[&](ByteBuffer const& buffer) -> ErrorOr<void> {
|
||||
request.set_body(buffer);
|
||||
return {};
|
||||
},
|
||||
[&](NonnullRefPtr<FileAPI::Blob> const& blob) -> ErrorOr<void> {
|
||||
auto byte_buffer = TRY(ByteBuffer::copy(blob->bytes()));
|
||||
request.set_body(byte_buffer);
|
||||
return {};
|
||||
},
|
||||
[](auto&) -> ErrorOr<void> {
|
||||
return {};
|
||||
}));
|
||||
if (body_with_type->type.has_value())
|
||||
request.set_header("Content-Type", String { body_with_type->type->span() });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue