Skip to content

Commit

Permalink
docs: update spec comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored and crysmags committed Feb 27, 2024
1 parent d2aade8 commit b5cb3f8
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,11 @@ function httpNetworkFetch (
// partition key given request.
// TODO

// 7. Switch on request’s mode:
// 7. Let newConnection be "yes" if forceNewConnection is true; otherwise
// "no".
const newConnection = forceNewConnection ? 'yes' : 'no'

// 8. Switch on request’s mode:
if (request.mode === 'websocket') {
// Let connection be the result of obtaining a WebSocket connection,
// given request’s current URL.
Expand All @@ -1596,7 +1600,7 @@ function httpNetworkFetch (
// TODO
}

// 8. Run these steps, but abort when the ongoing fetch is terminated:
// 9. Run these steps, but abort when the ongoing fetch is terminated:
// TODO: When do we cleanup this listener?
context.on('terminated', onRequestAborted)

Expand Down Expand Up @@ -1692,7 +1696,7 @@ function httpNetworkFetch (
}
})()

// 9. If aborted, then:
// 10. If aborted, then:
function onRequestAborted () {
// 1. Let aborted be the termination’s aborted flag.
const aborted = this.terminated.aborted
Expand All @@ -1709,26 +1713,26 @@ function httpNetworkFetch (
return resolve(makeNetworkError(this.terminated.reason))
}

// 10. Let pullAlgorithm be an action that resumes the ongoing fetch
// 11. Let pullAlgorithm be an action that resumes the ongoing fetch
// if it is suspended.
let pullAlgorithm

// 11. Let cancelAlgorithm be an action that terminates the ongoing
// 12. Let cancelAlgorithm be an action that terminates the ongoing
// fetch with the aborted flag set.
const cancelAlgorithm = () => {
context.terminate({ aborted: true })
}

// 12. Let highWaterMark be a non-negative, non-NaN number, chosen by
// 13. Let highWaterMark be a non-negative, non-NaN number, chosen by
// the user agent.
const highWaterMark = 64 * 1024 // Same as nodejs fs streams.

// 13. Let sizeAlgorithm be an algorithm that accepts a chunk object
// 14. Let sizeAlgorithm be an algorithm that accepts a chunk object
// and returns a non-negative, non-NaN, non-infinite number, chosen by the user agent.
// TODO

// 14. Let stream be a new ReadableStream.
// 15. Set up stream with pullAlgorithm set to pullAlgorithm,
// 15. Let stream be a new ReadableStream.
// 16. Set up stream with pullAlgorithm set to pullAlgorithm,
// cancelAlgorithm set to cancelAlgorithm, highWaterMark set to
// highWaterMark, and sizeAlgorithm set to sizeAlgorithm.
if (!ReadableStream) {
Expand Down Expand Up @@ -1757,23 +1761,14 @@ function httpNetworkFetch (
{ highWaterMark }
)

// 16. Run these steps, but abort when the ongoing fetch is terminated:
// TODO
// 17. Run these steps, but abort when the ongoing fetch is terminated:
// NOTE: See onHeaders.

// 17. If aborted, then:
// TODO: How can this happen? The steps above are not async?

// 18. Run these steps in parallel:
// 1. Run these steps, but abort when the ongoing fetch is terminated:
// 1. While true:
// 1. If one or more bytes have been transmitted from response’s
// message body, then:
// NOTE: See onHeaders
// 2. Otherwise, if the bytes transmission for response’s message
// body is done normally and stream is readable, then close stream,
// finalize response for fetchParams and response, and abort these
// in-parallel steps.
// NOTE: See onHeaders
// 18. If aborted, then:
// NOTE: See onHeaders.

// 19. Run these steps in parallel:
// NOTE: See onHeaders

// 2. If aborted, then:
function onResponseAborted () {
Expand Down Expand Up @@ -1801,7 +1796,7 @@ function httpNetworkFetch (
this.connection.destroy()
}

// 19. Return response.
// 20. Return response.
// NOTE: See onHeaders

// Implementation
Expand Down Expand Up @@ -1844,13 +1839,29 @@ function httpNetworkFetch (
)
}

// 17.1. Set response’s body to a new body whose stream is stream.
response = makeResponse({
status,
statusText,
headersList: headers[kHeadersList],
body: { stream }
})

// 17.2. If response is not a network error and request’s cache mode is not
// "no-store", then update response in httpCache for request.
// TODO
// 17.3. If includeCredentials is true and the user agent is not configured
// to block cookies for request (see section 7 of [COOKIES]), then run the
// "set-cookie-string" parsing algorithm (see section 5.2 of [COOKIES]) on
// the value of each header whose name is a byte-case-insensitive match for
// `Set-Cookie` in response’s header list, if any, and request’s current URL.
// TODO

// 18.1. If fetchParams is aborted, then set response’s aborted flag.
// TODO
// 18.2. Return response.
// TODO

this.context.on('terminated', onResponseAborted)

const codings =
Expand Down

0 comments on commit b5cb3f8

Please sign in to comment.