From f569c49e849e29d2baba7636463f3100632257c3 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 12 Jan 2022 12:28:16 +0100 Subject: [PATCH] fix: fetch improve finaly spec compliance --- lib/fetch/index.js | 54 +++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 7057c4e1066..a0b7f5f923c 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -742,30 +742,44 @@ function finalizeResponse (fetchParams, response) { function fetchFinale (fetchParams, response) { const context = this - // 1. If fetchParams’s process response is non-null, - // then queue a fetch task to run fetchParams’s process response - // given response, with fetchParams’s task destination. + // 1. If response is a network error, then: + if (response.type === 'error') { + // 1. Set response’s URL list to « fetchParams’s request’s URL list[0] ». + response.urlList = [fetchParams.request.urlList[0]] + + // 2. Set response’s timing info to the result of creating an opaque timing + // info for fetchParams’s timing info. + response.timingInfo = createOpaqueTimingInfo({ + startTime: fetchParams.timingInfo.startTime + }) + } + + // 2. Let processResponseEndOfBody be the following steps: + // TODO + + // 3. If fetchParams’s process response is non-null, then queue a fetch task + // to run fetchParams’s process response given response, with fetchParams’s + // task destination. if (fetchParams.processResponse != null) { fetchParams.processResponse(response) } - // 2. If fetchParams’s process response consume is non-null, then:. - // TODO - // 1. Let processBody given nullOrBytes be this step: run fetchParams’s - // process response consume given response and nullOrBytes.on. - // TODO - // 2. Let processBodyError be this step: run fetchParams’s process - // response consume given response and failure.on. - // TODO - // 3. If response’s body is null, then queue a fetch task to run - // processBody given null, with fetchParams’s task destination.on. - // TODO - // 4. Otherwise, fully read response’s body given processBody, - // processBodyError, and fetchParams’s task destination.on. - // TODO - - // TODO (spec): The spec doesn't specify this but we need to - // terminate fetch if we have an error response. + // 4. If fetchParams’s process response is non-null, then queue a fetch task + // to run fetchParams’s process response given response, with fetchParams’s + // task destination. + // TODO + + // 5. If response’s body is null, then run processResponseEndOfBody. + // TODO + + // 6. Otherwise: + // TODO + + // 7. If fetchParams’s process response consume body is non-null, then: + // TODO + + // TODO: This is a workaround. Until the above has been implemented, i.e. + // we need to either fully consume the body or terminate the fetch. if (response.type === 'error') { context.terminate({ reason: response.error }) }