Skip to content

Commit

Permalink
fix: fetch improve finaly spec compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jan 12, 2022
1 parent 6c69c19 commit f569c49
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions lib/fetch/index.js
Expand Up @@ -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 })
}
Expand Down

0 comments on commit f569c49

Please sign in to comment.