Skip to content

Commit

Permalink
LibWeb/Fetch: Handle streams on abort
Browse files Browse the repository at this point in the history
When aborting fetch, the request stream now gets closed and the
response stream errors.
  • Loading branch information
Glenn Skrzypczak committed Oct 19, 2024
1 parent 0b318e1 commit 7ceb454
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void abort_fetch(JS::Realm& realm, WebIDL::Promise const& promise, JS::NonnullGC

// 2. If request’s body is non-null and is readable, then cancel request’s body with error.
if (auto* body = request->body().get_pointer<JS::NonnullGCPtr<Infrastructure::Body>>(); body != nullptr && (*body)->stream()->is_readable()) {
// TODO: Implement cancelling streams
(void)error;
// NOTE: Cancel here is different than the cancel method of stream and refers to https://streams.spec.whatwg.org/#readablestream-cancel
Streams::readable_stream_cancel((*body)->stream(), error);
}

// 3. If responseObject is null, then return.
Expand All @@ -180,8 +180,7 @@ void abort_fetch(JS::Realm& realm, WebIDL::Promise const& promise, JS::NonnullGC
if (response->body()) {
auto stream = response->body()->stream();
if (stream->is_readable()) {
// TODO: Implement erroring streams
(void)error;
stream->error(error);
}
}
}
Expand Down

0 comments on commit 7ceb454

Please sign in to comment.