LibWeb: Handover the fetch response's internal body data upon completion

These is a normative change to the Fetch spec. See:
9003266
b5a587b
This commit is contained in:
Timothy Flynn 2023-05-26 09:42:26 -04:00 committed by Andreas Kling
parent 258f3ea952
commit 6406a561ef
Notes: sideshowbarker 2024-07-17 07:08:37 +09:00

View file

@ -628,20 +628,23 @@ WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm& realm, Infrastructu
});
}
// 5. If responses body is null, then run processResponseEndOfBody.
if (!response.body().has_value()) {
// 5. Let internalResponse be response, if response is a network error; otherwise responses internal response.
auto internal_response = response.is_network_error() ? JS::NonnullGCPtr { response } : response.unsafe_response();
// 6. If internalResponses 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 responses bodys stream to the result of responses bodys stream piped through transformStream.
// FIXME: 4. Set internalResponses bodys stream to the result of internalResponses bodys stream piped through transformStream.
}
// 7. If fetchParamss process response consume body is non-null, then:
// 8. If fetchParamss 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 fetchParamss 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 responses body is null, then queue a fetch task to run processBody given null, with fetchParamss
// 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
// fetchParamss 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 responses body given processBody, processBodyError, and fetchParamss task
// 4. Otherwise, fully read internalResponse body given processBody, processBodyError, and fetchParamss 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()));
}
}