Skip to content

Commit

Permalink
Use response's internal response at end of fetch handover
Browse files Browse the repository at this point in the history
This ensures that callers of processResponseEndOfBody and processResponseConsumeBody receive the correct body and response without additional steps.

Closes #1512.
  • Loading branch information
noamr committed May 22, 2023
1 parent 6f032a2 commit 9003266
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4817,7 +4817,11 @@ steps:
<a for="fetch params">process response</a> given <var>response</var>, with <var>fetchParams</var>'s
<a for="fetch params">task destination</a>.

<li><p>If <var>response</var>'s <a for=response>body</a> is null, then run
<li><p>Let <var>internalResponse</var> be <var>response</var>, if <var>response</var> is a
<a>network error</a>; otherwise <var>response</var>'s
<a for="filtered response">internal response</a>.

<li><p>If <var>internalResponse</var>'s <a for=response>body</a> is null, then run
<var>processResponseEndOfBody</var>.

<li>
Expand All @@ -4835,8 +4839,8 @@ steps:
<a for="TransformStream/set up"><i>flushAlgorithm</i></a> set to
<var>processResponseEndOfBody</var>.

<li><p>Set <var>response</var>'s <a for=response>body</a>'s <a for=body>stream</a> to the result
of <var>response</var>'s <a for=response>body</a>'s <a for=body>stream</a>
<li><p>Set <var>internalResponse</var>'s <a for=response>body</a>'s <a for=body>stream</a> to the
result of <var>internalResponse</var>'s <a for=response>body</a>'s <a for=body>stream</a>
<a for=ReadableStream>piped through</a> <var>transformStream</var>.
</ol>

Expand All @@ -4850,18 +4854,19 @@ steps:
<ol>
<li><p>Let <var>processBody</var> given <var>nullOrBytes</var> be this step: run
<var>fetchParams</var>'s <a for="fetch params">process response consume body</a> given
<var>response</var> and <var>nullOrBytes</var>.
<var>internalResponse</var> and <var>nullOrBytes</var>.

<li><p>Let <var>processBodyError</var> be this step: run <var>fetchParams</var>'s
<a for="fetch params">process response consume body</a> given <var>response</var> and failure.
<a for="fetch params">process response consume body</a> given <var>internalResponse</var> and
failure.

<li><p>If <var>response</var>'s <a for=response>body</a> is null, then <a>queue a fetch task</a>
to run <var>processBody</var> given null, with <var>fetchParams</var>'s
<li><p>If <var>internalResponse</var>'s <a for=response>body</a> is null, then
<a>queue a fetch task</a> to run <var>processBody</var> given null, with <var>fetchParams</var>'s
<a for="fetch params">task destination</a>.

<li><p>Otherwise, <a for=body>fully read</a> <var>response</var>'s <a for=response>body</a> given
<var>processBody</var>, <var>processBodyError</var>, and <var>fetchParams</var>'s
<a for="fetch params">task destination</a>.
<li><p>Otherwise, <a for=body>fully read</a> <var>internalResponse</var>'s
<a for=response>body</a> given <var>processBody</var>, <var>processBodyError</var>, and
<var>fetchParams</var>'s <a for="fetch params">task destination</a>.
</ol>
</ol>
</div>
Expand Down Expand Up @@ -8812,8 +8817,16 @@ particular at what stage you would like to receive a callback:
<a for=response>body</a> failed, e.g., due to an I/O error.

<dt>a <a>byte sequence</a>
<dd><a for=body>Fully reading</a> the contents of the <a for=/>response</a>'s
<a for=response>body</a> succeeded.
<dd>
<p><a for=body>Fully reading</a> the contents of the <a for=/>response</a>'s
<a for=response>body</a> succeeded.

<p class=warning>A <a>byte sequence</a> containing the full contents will be passed also for a
<a for=/>request</a> whose <a for=request>mode</a> is "<code>no-cors</code>". Callers have to
be careful when handling such content, as it should not be accessible to the requesting
<a for=/>origin</a>. For example, the caller may use contents of a "<code>no-cors</code>"
<a for=/>response</a> to display image contents directly to the user, but those image contents
should not be directly exposed to scripts in the embedding document.
</dl>

<div id=example-callback-upon-completion class=example>
Expand Down

0 comments on commit 9003266

Please sign in to comment.