Skip to content

Commit dc0f9e7

Browse files
authored
Add support for blob: URL range requests
Tests: web-platform-tests/wpt#34384 & web-platform-tests/wpt#37569. Fixes #1070.
1 parent e4f6c00 commit dc0f9e7

File tree

1 file changed

+95
-11
lines changed

1 file changed

+95
-11
lines changed

fetch.bs

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4882,21 +4882,105 @@ steps:
48824882
<p class=note>The `<code>GET</code>` <a for=/>method</a> restriction serves no useful purpose
48834883
other than being interoperable.
48844884

4885-
<li><p>Let <var>bodyWithType</var> be the result of <a for=BodyInit>safely extracting</a>
4886-
<var>blobURLEntry</var>'s <a for="blob URL entry">object</a>.
4885+
<li><p>Let <var>response</var> be a new <a for=/>response</a>.
48874886

4888-
<li><p>Let <var>body</var> be <var>bodyWithType</var>'s <a for="body with type">body</a>.
4889-
4890-
<li><p>Let <var>length</var> be <var>body</var>'s <a for=body>length</a>,
4887+
<li><p>Let <var>fullLength</var> be <var>blobURLEntry</var>'s
4888+
<a for="blob URL entry">object</a>'s {{Blob/size}},
48914889
<a lt="serialize an integer">serialized</a> and <a>isomorphic encoded</a>.
48924890

4893-
<li><p>Let <var>type</var> be <var>bodyWithType</var>'s <a for="body with type">type</a> if it
4894-
is non-null; otherwise the empty byte sequence.
4891+
<li><p>Let <var>type</var> be <var>blobURLEntry</var>'s
4892+
<a for="blob URL entry">object</a>'s {{Blob/type}}.
48954893

4896-
<li><p>Return a new <a for=/>response</a> whose <a for=response>status message</a> is
4897-
`<code>OK</code>`, <a for=response>header list</a> is « (`<code>Content-Length</code>`,
4898-
<var>length</var>), (`<code>Content-Type</code>`, <var>type</var>) », and
4899-
<a for=response>body</a> is <var>body</var>.
4894+
<li>
4895+
<p>If <var>request</var>'s <a for=request>header list</a>
4896+
<a for="header list">does not contain</a> `<code>Range</code>`:
4897+
4898+
<ol>
4899+
<li><p>Let <var>bodyWithType</var> be the result of <a for=BodyInit>safely extracting</a>
4900+
<var>blobURLEntry</var>'s <a for="blob URL entry">object</a>.
4901+
4902+
<li><p>Set <var>response</var>'s <a for=response>status message</a> to `<code>OK</code>`.
4903+
4904+
<li><p>Set <var>response</var>'s <a for=response>body</a> to <var>bodyWithType</var>'s
4905+
<a for="body with type">body</a>.
4906+
4907+
<li><p>Set <var>response</var>'s <a for=response>header list</a> to «
4908+
(`<code>Content-Length</code>`, <var>fullLength</var>), (`<code>Content-Type</code>`,
4909+
<var>type</var>) ».
4910+
</ol>
4911+
4912+
<li>
4913+
<p>Otherwise:
4914+
4915+
<ol>
4916+
<li><p>Set <var>response</var>'s <a for=response>range-requested flag</a>.
4917+
4918+
<li><p>Let <var>rangeHeader</var> be the result of <a for="header list">getting</a>
4919+
`<code>Range</code>` from <var>request</var>'s <a for=request>header list</a>.
4920+
<!-- Range should be added to the headers defined in HTTP extensions. See
4921+
https://github.com/whatwg/fetch/issues/1553 for future work -->
4922+
4923+
<li><p>Let <var>rangeValue</var> be the result of <a>parsing a single range header value</a>
4924+
given <var>rangeHeader</var> and true.
4925+
4926+
<li><p>If <var>rangeValue</var> is failure, then return a <a>network error</a>.
4927+
4928+
<li><p>Let <var>sliceEndRange</var> be null.
4929+
4930+
<li>
4931+
<p>If <var>rangeValue</var>[1] is non-null, then set <var>sliceEndRange</var> to
4932+
<var>rangeValue</var>[1] + 1.
4933+
4934+
<p class=note>A range header denotes an inclusive byte range, while the <a>slice blob</a>
4935+
algorithm input range does not. To use the <a>slice blob</a> algorithm, we have to increment
4936+
the parsed range header end value.
4937+
4938+
<li><p>Let <var>slicedBlob</var> be the result of invoking <a>slice blob</a> given
4939+
<var>blobURLEntry</var>'s <a for="blob URL entry">object</a>, <var>rangeValue</var>[0],
4940+
<var>sliceEndRange</var>, and <var>type</var>.
4941+
4942+
<li><p>Let <var>slicedBodyWithType</var> be the result of
4943+
<a for=BodyInit>safely extracting</a> <var>slicedBlob</var>.
4944+
4945+
<li><p>Set <var>response</var>'s <a for=response>body</a> to <var>slicedBodyWithType</var>'s
4946+
<a for="body with type">body</a>.
4947+
4948+
<li><p>Let <var>slicedLength</var> be <var>slicedBlob</var>'s {{Blob/size}},
4949+
<a lt="serialize an integer">serialized</a> and <a>isomorphic encoded</a>.
4950+
4951+
<!-- The following steps for content-range should be definined in a separate algorithm.
4952+
See https://github.com/whatwg/fetch/issues/1552 for future work -->
4953+
<li><p>Let <var>contentRange</var> be `<code>bytes </code>`.
4954+
4955+
<li><p>If <var>rangeValue</var>[0] is non-null, then
4956+
<a lt="serialize an integer">serialize</a> and <a>isomorphic encode</a>
4957+
<var>rangeValue</var>[0], and append the result to <var>contentRange</var>.
4958+
4959+
<li><p>Otherwise, append 0x30 (0) to <var>contentRange</var>.
4960+
4961+
<li><p>Append 0x2D (-) to <var>contentRange</var>.
4962+
4963+
<li><p>If <var>sliceEndRange</var> is non-null, then
4964+
<a lt="serialize an integer">serialize</a> and <a>isomorphic encode</a>
4965+
<var>sliceEndRange</var>, and append the result to <var>contentRange</var>.
4966+
4967+
<li><p>Otherwise, append <var>fullLength</var> to <var>contentRange</var>.
4968+
4969+
<li><p>Append 0x2F (/) to <var>contentRange</var>.
4970+
4971+
<li><p>Append <var>fullLength</var> to <var>contentRange</var>.
4972+
4973+
<li><p>Set <var>response</var>'s <a for=response>status</a> to 206.
4974+
4975+
<li><p>Set <var>response</var>'s <a for=response>status message</a> to
4976+
`<code>Partial Content</code>`.
4977+
4978+
<li><p>Set <var>response</var>'s <a for=response>header list</a> to «
4979+
(`<code>Content-Length</code>`, <var>slicedLength</var>), (`<code>Content-Type</code>`,
4980+
<var>type</var>), (`<code>Content-Range</code>`, <var>contentRange</var>) ».
4981+
</ol>
4982+
4983+
<li><p>Return <var>response</var>.
49004984
</ol>
49014985

49024986
<dt>"<code>data</code>"

0 commit comments

Comments
 (0)