Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/web/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,23 +1080,17 @@ function fetchFinale (fetchParams, response) {
if (internalResponse.body == null) {
processResponseEndOfBody()
} else {
// mcollina: all the following steps of the specs are skipped.
// The internal transform stream is not needed.
//
// 1. Let transformStream be a new TransformStream.
// 2. Let identityTransformAlgorithm be an algorithm which, given chunk, enqueues chunk in transformStream.
// 3. Set up transformStream with transformAlgorithm set to identityTransformAlgorithm and flushAlgorithm
// set to processResponseEndOfBody.
const transformStream = new TransformStream({
start () { },
transform (chunk, controller) {
controller.enqueue(chunk)
},
flush: processResponseEndOfBody
})

// 4. Set internalResponse’s body’s stream to the result of internalResponse’s body’s stream piped through transformStream.
internalResponse.body.stream.pipeThrough(transformStream)

const byteStream = new ReadableStream({
readableStream: transformStream.readable,
readableStream: internalResponse.body.stream,
async start () {
this._bodyReader = this.readableStream.getReader()
},
Expand All @@ -1105,7 +1099,12 @@ function fetchFinale (fetchParams, response) {
const { done, value } = await this._bodyReader.read()

if (done) {
queueMicrotask(() => readableStreamClose(controller))
queueMicrotask(() => {
readableStreamClose(controller)

// Added to in lieu of steps 1-4 of the spec
processResponseEndOfBody()
})
break
}

Expand Down