Skip to content

Commit 6744b8a

Browse files
committed
Add the validate a partial response algorithm and the extract content-range values algorithm
1 parent 302b545 commit 6744b8a

File tree

1 file changed

+114
-1
lines changed

1 file changed

+114
-1
lines changed

fetch.bs

+114-1
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,6 @@ and a <a for=/>response</a> <var>response</var>, is to run these steps:
33393339
<li><p>If <var>response</var>'s <a for=response>status</a> is 206 and
33403340
<a>validate a partial response</a> given 0 and <var>response</var> returns invalid, then return
33413341
false.
3342-
<!-- TODO Integrate https://wicg.github.io/background-fetch/#validate-a-partial-response into Fetch -->
33433342

33443343
<li><p>Let <var>bytes</var> be the result of running
33453344
<a>obtain a copy of the first 1024 bytes of response</a> given <var>response</var>.
@@ -3387,6 +3386,81 @@ and a <a for=/>response</a> <var>response</var>, is to run these steps:
33873386

33883387
<hr>
33893388

3389+
<div algorithm>
3390+
<p>To <dfn>extract content-range values</dfn>, given an <a for=/>response</a> <var>response</var>
3391+
run these steps:<p>
3392+
3393+
<ol>
3394+
<li><p>If <var>response</var>’s <a for=response>header list</a> <a for="header list">does not contain</a> `<code>Content-Range</code>`, then return failure.
3395+
3396+
<li><p>Let <var>contentRangeValue</var> be the <a lt=value for=header>value</a> of the first <a for=/>header</a> whose <a for=header>name</a> is a
3397+
<a>byte-case-insensitive</a> match for `<code>Content-Range</code>` in <var>response</var>’s <a for=response>header list</a>.
3398+
3399+
<li><p>If parsing <var>contentRangeValue</var> per <a>single byte content-range</a> fails, then return failure.
3400+
3401+
<li><p>Let <var>firstBytePos</var> be the portion of <var>contentRangeValue</var> named
3402+
first-byte-pos when parsed as <a>single byte content-range</a>, parsed as an integer.
3403+
3404+
<li><p>Let <var>lastBytePos</var> be the portion of <var>contentRangeValue</var> named
3405+
last-byte-pos when parsed as <a>single byte content-range</a>, parsed as an integer.
3406+
3407+
<li><p>Let <var>completeLength</var> be the portion of <var>contentRangeValue</var> named
3408+
complete-length when parsed as <a>single byte content-range</a>.
3409+
3410+
<li><p>If <var>completeLength</var> is "<code>*</code>", then set <var>completeLength</var> to null, otherwise
3411+
set <var>completeLength</var> to <var>completeLength</var> parsed as an integer.
3412+
3413+
<li><p>Return <var>firstBytePos</var>, <var>lastBytePos</var>, and <var>completeLength</var>.
3414+
</ol>
3415+
3416+
<p class=XXX>Parsing as an integer <a href="https://github.com/whatwg/infra/issues/189">infra/189</a>
3417+
</div>
3418+
3419+
<hr>
3420+
3421+
<div algorithm>
3422+
<p>To <dfn>validate a partial response</dfn>, given an integer <var>expectedRangeStart</var> , a
3423+
<a for=/>response</a> <var>partialResponse</var>, and an optional <a for=/>response</a> <var>previousResponse</var> (default null),
3424+
run these steps:</p>
3425+
3426+
<ol>
3427+
<li><p>Assert: <var>partialResponse</var>'s <a for=response>status</a> is `206`.
3428+
3429+
<li><p>Let <var>responseFirstBytePos</var>, <var ignore>responseLastBytePos</var>, and <var>responseCompleteLength</var> be the
3430+
result of <a>extracting content-range values</a> from <var>partialResponse</var>. If this fails, then return invalid.
3431+
3432+
<li><p>If <var>responseFirstBytePos</var> does not equal <var>expectedRangeStart</var>, then return invalid.
3433+
3434+
<li><p>If <var>previousResponse</var> is not null, then:
3435+
3436+
<ol>
3437+
<li><p>For <var>headerName</var> of « `<code>ETag</code>`, `<code>Last-Modified</code>` »:
3438+
3439+
<ol>
3440+
<li>If <var>previousResponse</var>'s <a for=response>header list</a> <a for="header list">contains</a> <var>headerName</var>
3441+
and the <a for="header list">combined</a> value of <var>headerName</var>
3442+
in <var>previousResponse</var>'s <a for=response>header list</a> does not equal the
3443+
<a for="header list">combined</a> value of <var>headerName</var> in <var>partialResponse</var>'s
3444+
<a for=response>header list</a>, then return invalid.
3445+
</ol>
3446+
3447+
<li><p>If <var>previousResponse</var>'s <a for=response>status</a> is 206, then:
3448+
3449+
<ol>
3450+
<li><p>Let <var ignore>previousResponseFirstBytePos</var>, <var ignore>previousResponseLastBytePos</var>,
3451+
and <var>previousResponseCompleteLength</var> be the result of <a>extracting content-range values</a>
3452+
from <var>previousResponse</var>. If this fails, then return invalid.
3453+
3454+
<li><p>If <var>previousResponseCompleteLength</var> is not null, and
3455+
<var>responseCompleteLength</var> does not equal <var>previousResponseCompleteLength</var>, then return invalid.
3456+
</ol>
3457+
</ol>
3458+
<li>Return valid.
3459+
</ol>
3460+
</div>
3461+
3462+
<hr>
3463+
33903464
<p>To <dfn>obtain a copy of the first 1024 bytes of response</dfn>, given a <a for=/>response</a>
33913465
<var>response</var>, run these steps:
33923466

@@ -3808,6 +3882,45 @@ response <a for=/>headers</a>, the <a for=header>value</a> `<code>*</code>` coun
38083882
<a for=/>requests</a> without <a for=/>credentials</a>. For such <a for=/>requests</a> there is no
38093883
way to solely match a <a for=/>header name</a> or <a for=/>method</a> that is `<code>*</code>`.
38103884

3885+
<p><a>ABNF</a> for a <dfn export> single byte content-range</dfn>:
3886+
3887+
<pre><code class=lang-abnf>
3888+
"bytes=" first-byte-pos "-" last-byte-pos "/" complete-length
3889+
first-byte-pos = 1*DIGIT
3890+
last-byte-pos = 1*DIGIT
3891+
complete-length = ( 1*DIGIT / "*" )
3892+
</code></pre>
3893+
3894+
<p class=note>This is a subset of what <a href="https://tools.ietf.org/html/rfc7233#section-3.1">RFC 7233</a> allows.
3895+
3896+
<div class="note">
3897+
3898+
The above as a railroad diagram:
3899+
3900+
<pre class="railroad">
3901+
T: "bytes="
3902+
Stack:
3903+
Sequence:
3904+
Comment: first-byte-pos
3905+
OneOrMore:
3906+
N: digit
3907+
Comment: /first-byte-pos
3908+
N: "/"
3909+
Sequence:
3910+
Comment: last-byte-pos
3911+
OneOrMore:
3912+
N: digit
3913+
Comment: /last-byte-pos
3914+
N: "/"
3915+
Sequence:
3916+
Comment: complete-length
3917+
Choice:
3918+
N: "*"
3919+
OneOrMore:
3920+
N: digit
3921+
Comment: /complete-length
3922+
</pre>
3923+
</div>
38113924

38123925
<h4 id=cors-protocol-and-credentials>CORS protocol and credentials</h4>
38133926

0 commit comments

Comments
 (0)