diff --git a/fetch.bs b/fetch.bs index a6afc985f..9a86075bc 100644 --- a/fetch.bs +++ b/fetch.bs @@ -182,7 +182,7 @@ lt="authentication entry">authentication entries (for HTTP authentication). steps:
If taskDestination is a parallel queue, then +
If taskDestination is a parallel queue, then enqueue algorithm to taskDestination. @@ -1004,25 +1004,12 @@ worked on in issue #1156
A stream (null or a {{ReadableStream}} object). -
A transmitted bytes - (an integer), initially 0. -
A total bytes (an integer), initially 0.
A source, initially null. -
A body body is said to be -done if body is null or -body's stream is -closed or -errored. - -
To wait for a -body body, wait for body to be -done. -
To clone a body body, run these steps: @@ -1037,6 +1024,124 @@ worked on in issue #1156 body.
To incrementally read a body body, given an +algorithm processBodyChunk, an algorithm processEndOfBody, an algorithm +processBodyError, and an optional null, parallel queue, or +global object taskDestination (default null), run these steps. +processBodyChunk must be an algorithm accepting a byte sequence. +processEndOfBody must be an algorithm accepting no arguments. processBodyError +must be an algorithm accepting an exception. + +
If taskDestination is null, then set taskDestination to the result of + starting a new parallel queue. + +
Let reader be the result of getting a reader for + body's stream. + +
This operation ought not to throw an exception. + +
Perform the incrementally-read loop given reader, + taskDestination, processBodyChunk, processEndOfBody, and + processBodyError. +
To perform the incrementally-read loop, given a {{ReadableStreamDefaultReader}} object +reader, parallel queue or global object +taskDestination, algorithm processBodyChunk, algorithm +processEndOfBody, and algorithm processBodyError: + +
Let readRequest be the following read request: + +
Let continueAlgorithm be null. + +
If chunk is not a {{Uint8Array}} object, then set + continueAlgorithm to this step: run processBodyError given a + {{TypeError}}. + +
Otherwise: + +
Let bytes be a copy of + chunk. + +
Set continueAlgorithm to these steps: + +
Run processBodyChunk given bytes. + +
Perform the incrementally-read loop given reader, + taskDestination, processBodyChunk, processEndOfBody, and + processBodyError. +
Queue a fetch task given continueAlgorithm and + taskDestination. +
Queue a fetch task given processEndOfBody and + taskDestination.
Queue a fetch task to run processBodyError given e, + with taskDestination.
Read a chunk from reader given + readRequest. +
To fully read a body body, given an algorithm +processBody, an algorithm processBodyError, and an optional null, +parallel queue, or global object taskDestination (default +null), run these steps. processBody must be an algorithm accepting a +byte sequence. processBodyError must be an algorithm accepting no arguments. + +
If taskDestination is null, then set taskDestination to the result of + starting a new parallel queue. + +
Let promise be the result of fully reading body as promise given + body. + +
Let fulfilledSteps given a byte sequence bytes be to + queue a fetch task to run processBody given bytes, with + taskDestination. + +
Let rejectedSteps be to queue a fetch task to run + processBodyError, with taskDestination. + +
React to promise with fulfilledSteps and + rejectedSteps. +
To fully read body as promise, given a +body body, run these steps: + +
Let reader be the result of getting a reader for + body's stream. If that threw an exception, then return + a promise rejected with that exception. + +
Return the result of reading all bytes from + reader. +
To handle content codings given codings and bytes, run
these steps:
@@ -1654,126 +1759,6 @@ is to return the result of serializing a request origin with request
To transmit request body, given a
-fetch params fetchParams, run these steps:
-
- If body is null and fetchParams's
- process request end-of-body is non-null, then:
-
- Let processRequestEndOfBody be this step: run fetchParams's
- process request end-of-body given fetchParams's
- request.
-
- Queue a fetch task given processRequestEndOfBody and
- fetchParams's task destination.
-
- Otherwise, if body is non-null:
-
- Let reader be the result of getting a reader for
- body's stream.
-
- This operation cannot throw an exception.
-
- Perform the transmit-request-body loop given fetchParams,
- body, and reader.
- To perform the transmit-request-body loop, given a fetch params
-fetchParams, body body, and {{ReadableStreamDefaultReader}}
-object reader:
-
- Let readRequest be the following read request:
-
- If the ongoing fetch is terminated, then abort these steps.
-
- If chunk is not a {{Uint8Array}} object,
- terminate the ongoing fetch and abort these steps.
-
- Let bs be the byte sequence represented by the {{Uint8Array}} object.
-
- Let processRequestBody be null.
-
- If fetchParams's process request body is non-null,
- then set processRequestBody to this step: run fetchParams's
- process request body given fetchParams's
- request.
-
- In parallel:
-
- Transmit bs. Whenever one or more bytes are transmitted, increase
- body's transmitted bytes by the number of transmitted bytes and
- if processRequestBody is non-null then queue a fetch task given
- processRequestBody and fetchParams's
- task destination.
-
- This step blocks until bs is fully transmitted.
-
- Let continueAlgorithm be this step: perform the
- transmit-request-body loop given fetchParams, body, and
- reader.
-
- If the ongoing fetch is not terminated, then
- queue a fetch task given continueAlgorithm and fetchParams's
- task destination.
- If the ongoing fetch is terminated, then abort these steps.
-
- If fetchParams's process request end-of-body is
- non-null, then:
-
- Let processRequestEndOfBody be this step: run fetchParams's
- process request end-of-body given fetchParams's
- request.
-
- Queue a fetch task given processRequestEndOfBody and
- fetchParams's task destination.
- If the ongoing fetch is terminated, then abort these steps.
-
- If e is an " Otherwise, terminate the ongoing fetch.
- Read a chunk from reader given
- readRequest.
- To add a range header to a
request request, with an integer first, and an optional integer
last, run these steps:
@@ -3241,9 +3226,11 @@ an optional algorithm processResp
optional algorithm
processResponseEndOfBody,
and an optional boolean useParallelQueue (default false), run
-the steps below. If given, processRequestBody and processRequestEndOfBody must
-be an algorithm accepting a request; processResponse and
-processResponseEndOfBody must be an algorithm accepting a response.
+the steps below. If given, processRequestBody must be an algorithm accepting an integer.
+If given, processRequestEndOfBody must be an algorithm accepting no arguments.
+processResponse must be an algorithm accepting a response.
+processResponseEndOfBody must be an algorithm accepting a response and null,
+failure, or a byte sequence.
An ongoing fetch can be
terminated with flag aborted,
@@ -3284,15 +3271,9 @@ the request.
process response end-of-body is processResponseEndOfBody, and
task destination is taskDestination.
- If request's body is a byte sequence, then:
-
- Let body and ignoreType be the result of
- safely extracting request's body.
-
- Set request's body to body.
- If request's body is a byte sequence, then set
+ request's body to the first return value of
+ safely extracting request's body.
If request's window is " This standardizes the error handling for servers that violate HTTP.
If response is not a network error and request's
- integrity metadata is not the empty string, then:
+ If request's integrity metadata is not the empty string, then:
If response's body's stream has not
- errored, and response does not
- match
- request's integrity metadata, set response and
- internalResponse to a network error.
- [[!SRI]]
- Let processBodyError be this step: run fetch finale given
+ fetchParams and a network error.
- This operates on response as this algorithm is not supposed to observe
- internalResponse. That would allow an attacker to use hashes as an oracle.
- If fetchParams's process response is non-null, then:
+ If request's response tainting is " Let processResponse be this step: run fetchParams's
- process response given response.
+ Let processBody given bytes be these steps:
- Queue a fetch task given processResponse and fetchParams's
- task destination.
+ If bytes do not
+ match
+ request's integrity metadata, then run
+ processBodyError and abort these steps. [[!SRI]]
+
+ Set response's body to the first return value of
+ safely extracting bytes.
+
+ Run fetch finale given fetchParams and response.
+ Fully read response's body given
+ processBody and processBodyError.
Otherwise, run fetch finale given fetchParams and response.
+ The fetch finale, given a fetch params fetchParams and a
+response response, run these steps:
+
+ 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.
Let doneAlgorithm be these steps:
+ If fetchParams's process response end-of-body is non-null,
+ then:
Set request's done flag.
+ Let processBody given nullOrFailureOrBytes be this step: run
+ fetchParams's process response end-of-body given
+ response and nullOrFailureOrBytes.
+
+ Let processBodyError be to run processBody given failure.
- If fetchParams's process response end-of-body is
- non-null, then run fetchParams's
- process response end-of-body given response.
+ If response's body is null, then queue a fetch task
+ to processBody given null, with fetchParams's
+ task destination.
+
+ Otherwise, fully read response's body given
+ processBody, processBodyError, and fetchParams's
+ task destination.
Queue a fetch task given doneAlgorithm and fetchParams's
- task destination.
+ Wait for either response's body to be null, or
+ response's body's stream to be
+ closed or errored, and then set
+ request's done flag.
+
Run these steps, but abort when the ongoing fetch is terminated:
@@ -4667,7 +4671,62 @@ these steps:
Otherwise, return a network error.
- Transmit request body given fetchParams.
+ To transmit request's body body, run these steps:
+
+ If body is null and fetchParams's
+ process request end-of-body is non-null, then
+ queue a fetch task given fetchParams's
+ process request end-of-body and fetchParams's
+ task destination.
+
+ Otherwise, if body is non-null:
+
+ Let processBodyChunk given bytes, be these steps:
+
+ If the ongoing fetch is terminated, then abort these steps.
+
+ Run this step in parallel: transmit bytes.
+
+ If fetchParams's process request body is
+ non-null, then run fetchParams's process request body
+ given bytes's length.
+ Let processEndOfBody be these steps:
+
+ If the ongoing fetch is terminated, then abort these steps.
+
+ If fetchParams's process request end-of-body is
+ non-null, then run fetchParams's
+ process request end-of-body.
+ Let processBodyError given e, be these steps:
+
+ If the ongoing fetch is terminated, then abort these steps.
+
+ If e is an " Otherwise, terminate the ongoing fetch.
+ Incrementally read request's body given
+ processBodyChunk, processEndOfBody, processBodyError, and
+ fetchParams's task destination.
+
+ Let promise be a promise resolved with an empty
byte sequence.
- If object's body is non-null, then:
-
- Let reader be the result of getting a reader from
- stream. If that threw an exception, then return a promise rejected with that
- exception.
-
- Set promise to the result of
- reading all bytes from reader.
- If object's body is non-null, then set promise to the
+ result of fully reading body as promise given object's body.
Let steps be to return the result of package data with the first argument
given, type, and object's MIME type.
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- AbortError
" {{DOMException}}, then
- terminate the ongoing fetch with the aborted flag set.
-
-
-
-
+ client
", then set
request's window to request's client,
@@ -3630,51 +3611,75 @@ steps:
-
+ opaque
",
+ response is a network error, or response's body
+ is null, then run processBodyError and abort these steps.
-
-
-
+
+
+
+
+
+
@@ -4617,7 +4622,6 @@ these steps:
includeCredentials.
-
-
-
+
@@ -5731,20 +5790,8 @@ the associated steps:
+
+
+
+
+
+
+
+
+
+
+ AbortError
" {{DOMException}},
+ then terminate the ongoing fetch with the aborted flag set.
+
+
-
+