LibWeb: Use URL's 'blob URL entry' for blob fetches

Performing a lookup in the blob URL registry does not work in the case
of a web worker - as the registry is not shared between processes.
However - the URL itself passed to a worker has the blob attached to it,
which we can pull out of the URL on a fetch.
This commit is contained in:
Shannon Booth 2024-05-05 20:39:13 +12:00 committed by Andrew Kaster
commit 53eb9af42f
Notes: sideshowbarker 2024-07-17 20:58:35 +09:00

View file

@ -731,10 +731,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm& r
}
// -> "blob"
else if (request->current_url().scheme() == "blob"sv) {
auto const& store = FileAPI::blob_url_store();
// 1. Let blobURLEntry be requests current URLs blob URL entry.
auto blob_url_entry = store.get(TRY_OR_THROW_OOM(vm, request->current_url().to_string()));
auto const& blob_url_entry = request->current_url().blob_url_entry();
// 2. If requests method is not `GET`, blobURLEntry is null, or blobURLEntrys object is not a Blob object,
// then return a network error. [FILEAPI]
@ -745,7 +743,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm& r
}
// 3. Let blob be blobURLEntrys object.
auto const& blob = blob_url_entry->object;
auto const blob = FileAPI::Blob::create(realm, blob_url_entry.value().byte_buffer, blob_url_entry.value().type);
// 4. Let response be a new response.
auto response = Infrastructure::Response::create(vm);
@ -762,7 +760,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm& r
// 8. If requests header list does not contain `Range`:
if (!request->header_list()->contains("Range"sv.bytes())) {
// 1. Let bodyWithType be the result of safely extracting blob.
auto body_with_type = TRY(safely_extract_body(realm, blob));
auto body_with_type = TRY(safely_extract_body(realm, blob->bytes()));
// 2. Set responses status message to `OK`.
response->set_status_message(MUST(ByteBuffer::copy("OK"sv.bytes())));