LibWeb: Set up the Fetch response's body with the appropriate stream
This commit is contained in:
parent
2bb751eab9
commit
09124fc3a5
Notes:
sideshowbarker
2024-07-16 20:08:14 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/09124fc3a5 Pull-request: https://github.com/SerenityOS/serenity/pull/22943 Issue: https://github.com/SerenityOS/serenity/issues/22933 Reviewed-by: https://github.com/kennethmyhra ✅
3 changed files with 23 additions and 5 deletions
1
Tests/LibWeb/Text/expected/Streams/init-from-fetch.txt
Normal file
1
Tests/LibWeb/Text/expected/Streams/init-from-fetch.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Was able to create a reader from a Fetch response!
|
14
Tests/LibWeb/Text/input/Streams/init-from-fetch.html
Normal file
14
Tests/LibWeb/Text/input/Streams/init-from-fetch.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
fetch("./../basic.html", { mode: "no-cors" })
|
||||
.then(response => response.body)
|
||||
.then(body => {
|
||||
const reader = body.getReader();
|
||||
reader.read();
|
||||
|
||||
println("Was able to create a reader from a Fetch response!");
|
||||
done();
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -8,7 +8,10 @@
|
|||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibWeb/Fetch/BodyInit.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
|
||||
#include <LibWeb/FileAPI/Blob.h>
|
||||
#include <LibWeb/HTML/FormControlInfrastructure.h>
|
||||
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
||||
#include <LibWeb/Streams/AbstractOperations.h>
|
||||
#include <LibWeb/URL/URLSearchParams.h>
|
||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
#include <LibWeb/WebIDL/Buffers.h>
|
||||
|
@ -33,6 +36,8 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> safely_extract_body(JS::Realm&
|
|||
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
|
||||
WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm, BodyInitOrReadableBytes const& object, bool keepalive)
|
||||
{
|
||||
HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
|
||||
auto& vm = realm.vm();
|
||||
|
||||
// 1. Let stream be null.
|
||||
|
@ -44,14 +49,12 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
|
|||
}
|
||||
// 3. Otherwise, if object is a Blob object, set stream to the result of running object’s get stream.
|
||||
else if (auto const* blob_handle = object.get_pointer<JS::Handle<FileAPI::Blob>>()) {
|
||||
// FIXME: "set stream to the result of running object’s get stream"
|
||||
(void)blob_handle;
|
||||
stream = realm.heap().allocate<Streams::ReadableStream>(realm, realm);
|
||||
stream = TRY(blob_handle->cell()->get_stream());
|
||||
}
|
||||
// 4. Otherwise, set stream to a new ReadableStream object, and set up stream.
|
||||
// 4. Otherwise, set stream to a new ReadableStream object, and set up stream with byte reading support.
|
||||
else {
|
||||
// FIXME: "set up stream"
|
||||
stream = realm.heap().allocate<Streams::ReadableStream>(realm, realm);
|
||||
TRY(Streams::set_up_readable_stream_controller_with_byte_reading_support(*stream));
|
||||
}
|
||||
|
||||
// 5. Assert: stream is a ReadableStream object.
|
||||
|
|
Loading…
Add table
Reference in a new issue