summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-05-26 09:42:26 -0400
committerAndreas Kling <kling@serenityos.org>2023-05-29 17:12:46 +0200
commit6406a561efc90fbd529c08cdfafce3ed15d84fc8 (patch)
tree35a50f840c924c3dd6190f601e8d6f34145931b1 /Userland
parent258f3ea95234d9229cdb8376b1aa256e4b312912 (diff)
downloadserenity-6406a561efc90fbd529c08cdfafce3ed15d84fc8.zip
LibWeb: Handover the fetch response's internal body data upon completion
These is a normative change to the Fetch spec. See: https://github.com/whatwg/fetch/commit/9003266 https://github.com/whatwg/fetch/commit/b5a587b
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index 5f1b837da4..b846ca21b4 100644
--- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -628,20 +628,23 @@ WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm& realm, Infrastructu
});
}
- // 5. If response’s body is null, then run processResponseEndOfBody.
- if (!response.body().has_value()) {
+ // 5. Let internalResponse be response, if response is a network error; otherwise response’s internal response.
+ auto internal_response = response.is_network_error() ? JS::NonnullGCPtr { response } : response.unsafe_response();
+
+ // 6. If internalResponse’s body is null, then run processResponseEndOfBody.
+ if (!internal_response->body().has_value()) {
process_response_end_of_body();
}
- // 6. Otherwise:
+ // 7. Otherwise:
else {
// FIXME: 1. Let transformStream be a new TransformStream.
// FIXME: 2. Let identityTransformAlgorithm be an algorithm which, given chunk, enqueues chunk in transformStream.
// FIXME: 3. Set up transformStream with transformAlgorithm set to identityTransformAlgorithm and flushAlgorithm set
// to processResponseEndOfBody.
- // FIXME: 4. Set response’s body’s stream to the result of response’s body’s stream piped through transformStream.
+ // FIXME: 4. Set internalResponse’s body’s stream to the result of internalResponse’s body’s stream piped through transformStream.
}
- // 7. If fetchParams’s process response consume body is non-null, then:
+ // 8. If fetchParams’s process response consume body is non-null, then:
if (fetch_params.algorithms()->process_response_consume_body().has_value()) {
// 1. Let processBody given nullOrBytes be this step: run fetchParams’s process response consume body given
// response and nullOrBytes.
@@ -655,17 +658,17 @@ WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm& realm, Infrastructu
(*fetch_params.algorithms()->process_response_consume_body())(response, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});
};
- // 3. If response’s body is null, then queue a fetch task to run processBody given null, with fetchParams’s
- // task destination.
- if (!response.body().has_value()) {
+ // 3. If internalResponse's body is null, then queue a fetch task to run processBody given null, with
+ // fetchParams’s task destination.
+ if (!internal_response->body().has_value()) {
Infrastructure::queue_fetch_task(task_destination, [process_body = move(process_body)]() {
process_body({});
});
}
- // 4. Otherwise, fully read response’s body given processBody, processBodyError, and fetchParams’s task
+ // 4. Otherwise, fully read internalResponse body given processBody, processBodyError, and fetchParams’s task
// destination.
else {
- TRY(response.body()->fully_read(realm, move(process_body), move(process_body_error), fetch_params.task_destination()));
+ TRY(internal_response->body()->fully_read(realm, move(process_body), move(process_body_error), fetch_params.task_destination()));
}
}