Skip to content

Commit e1f8129

Browse files
authored
Correct blob: URL range requests
In particular: * Return a network error when rangeStart is out-of-range. * If rangeStart is null, it should become fullLength - rangeEnd, not 0. rangeEnd then has to be adjusted as well. * If rangeEnd is out-of-range, it should become fullLength - 1. Tests: web-platform-tests/wpt#39108.
1 parent 764714d commit e1f8129

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

fetch.bs

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4886,31 +4886,33 @@ steps:
48864886
<p class=note>The `<code>GET</code>` <a for=/>method</a> restriction serves no useful purpose
48874887
other than being interoperable.
48884888

4889+
<li><p>Let <var>blob</var> be <var>blobURLEntry</var>'s <a for="blob URL entry">object</a>.
4890+
48894891
<li><p>Let <var>response</var> be a new <a for=/>response</a>.
48904892

4891-
<li><p>Let <var>fullLength</var> be <var>blobURLEntry</var>'s
4892-
<a for="blob URL entry">object</a>'s {{Blob/size}},
4893+
<li><p>Let <var>fullLength</var> be <var>blob</var>'s {{Blob/size}}.
4894+
4895+
<li><p>Let <var>serializedFullLength</var> be <var>fullLength</var>,
48934896
<a lt="serialize an integer">serialized</a> and <a>isomorphic encoded</a>.
48944897

4895-
<li><p>Let <var>type</var> be <var>blobURLEntry</var>'s
4896-
<a for="blob URL entry">object</a>'s {{Blob/type}}.
4898+
<li><p>Let <var>type</var> be <var>blob</var>'s {{Blob/type}}.
48974899

48984900
<li>
48994901
<p>If <var>request</var>'s <a for=request>header list</a>
49004902
<a for="header list">does not contain</a> `<code>Range</code>`:
49014903

49024904
<ol>
49034905
<li><p>Let <var>bodyWithType</var> be the result of <a for=BodyInit>safely extracting</a>
4904-
<var>blobURLEntry</var>'s <a for="blob URL entry">object</a>.
4906+
<var>blob</var>.
49054907

49064908
<li><p>Set <var>response</var>'s <a for=response>status message</a> to `<code>OK</code>`.
49074909

49084910
<li><p>Set <var>response</var>'s <a for=response>body</a> to <var>bodyWithType</var>'s
49094911
<a for="body with type">body</a>.
49104912

49114913
<li><p>Set <var>response</var>'s <a for=response>header list</a> to «
4912-
(`<code>Content-Length</code>`, <var>fullLength</var>), (`<code>Content-Type</code>`,
4913-
<var>type</var>) ».
4914+
(`<code>Content-Length</code>`, <var>serializedFullLength</var>),
4915+
(`<code>Content-Type</code>`, <var>type</var>) ».
49144916
</ol>
49154917

49164918
<li>
@@ -4929,59 +4931,70 @@ steps:
49294931

49304932
<li><p>If <var>rangeValue</var> is failure, then return a <a>network error</a>.
49314933

4932-
<li><p>Let <var>sliceEndRange</var> be null.
4934+
<li><p>Let (<var>rangeStart</var>, <var>rangeEnd</var>) be <var>rangeValue</var>.
4935+
4936+
<li>
4937+
<p>If <var>rangeStart</var> is null:
4938+
4939+
<ol>
4940+
<li><p>Set <var>rangeStart</var> to <var>fullLength</var> &minus; <var>rangeEnd</var>.
4941+
4942+
<li><p>Set <var>rangeEnd</var> to <var>rangeStart</var> + <var>rangeEnd</var> &minus; 1.
4943+
</ol>
4944+
4945+
<li>
4946+
<p>Otherwise:
4947+
4948+
<ol>
4949+
<li><p>If <var>rangeStart</var> is greater than or equal to <var>fullLength</var>, then
4950+
return a <a>network error</a>.
4951+
4952+
<li><p>If <var>rangeEnd</var> is null or <var>rangeEnd</var> is greater than or equal to
4953+
<var>fullLength</var>, then set <var>rangeEnd</var> to <var>fullLength</var> &minus; 1.
4954+
</ol>
49334955

49344956
<li>
4935-
<p>If <var>rangeValue</var>[1] is non-null, then set <var>sliceEndRange</var> to
4936-
<var>rangeValue</var>[1] + 1.
4957+
<p>Let <var>slicedBlob</var> be the result of invoking <a>slice blob</a> given
4958+
<var>blob</var>, <var>rangeStart</var>, <var>rangeEnd</var> + 1, and <var>type</var>.
49374959

49384960
<p class=note>A range header denotes an inclusive byte range, while the <a>slice blob</a>
49394961
algorithm input range does not. To use the <a>slice blob</a> algorithm, we have to increment
4940-
the parsed range header end value.
4941-
4942-
<li><p>Let <var>slicedBlob</var> be the result of invoking <a>slice blob</a> given
4943-
<var>blobURLEntry</var>'s <a for="blob URL entry">object</a>, <var>rangeValue</var>[0],
4944-
<var>sliceEndRange</var>, and <var>type</var>.
4962+
<var>rangeEnd</var>.
49454963

49464964
<li><p>Let <var>slicedBodyWithType</var> be the result of
49474965
<a for=BodyInit>safely extracting</a> <var>slicedBlob</var>.
49484966

49494967
<li><p>Set <var>response</var>'s <a for=response>body</a> to <var>slicedBodyWithType</var>'s
49504968
<a for="body with type">body</a>.
49514969

4952-
<li><p>Let <var>slicedLength</var> be <var>slicedBlob</var>'s {{Blob/size}},
4970+
<li><p>Let <var>serializedSlicedLength</var> be <var>slicedBlob</var>'s {{Blob/size}},
49534971
<a lt="serialize an integer">serialized</a> and <a>isomorphic encoded</a>.
49544972

49554973
<!-- The following steps for content-range should be definined in a separate algorithm.
49564974
See https://github.com/whatwg/fetch/issues/1552 for future work -->
49574975
<li><p>Let <var>contentRange</var> be `<code>bytes </code>`.
49584976

4959-
<li><p>If <var>rangeValue</var>[0] is non-null, then
4960-
<a lt="serialize an integer">serialize</a> and <a>isomorphic encode</a>
4961-
<var>rangeValue</var>[0], and append the result to <var>contentRange</var>.
4962-
4963-
<li><p>Otherwise, append 0x30 (0) to <var>contentRange</var>.
4977+
<li><p>Append <var>rangeStart</var>, <a lt="serialize an integer">serialized</a> and
4978+
<a>isomorphic encoded</a>, to <var>contentRange</var>.
49644979

49654980
<li><p>Append 0x2D (-) to <var>contentRange</var>.
49664981

4967-
<li><p>If <var>sliceEndRange</var> is non-null, then
4968-
<a lt="serialize an integer">serialize</a> and <a>isomorphic encode</a>
4969-
<var>sliceEndRange</var>, and append the result to <var>contentRange</var>.
4970-
4971-
<li><p>Otherwise, append <var>fullLength</var> to <var>contentRange</var>.
4982+
<li><p>Append <var>rangeEnd</var>, <a lt="serialize an integer">serialized</a> and
4983+
<a>isomorphic encoded</a> to <var>contentRange</var>.
49724984

49734985
<li><p>Append 0x2F (/) to <var>contentRange</var>.
49744986

4975-
<li><p>Append <var>fullLength</var> to <var>contentRange</var>.
4987+
<li><p>Append <var>serializedFullLength</var> to <var>contentRange</var>.
49764988

49774989
<li><p>Set <var>response</var>'s <a for=response>status</a> to 206.
49784990

49794991
<li><p>Set <var>response</var>'s <a for=response>status message</a> to
49804992
`<code>Partial Content</code>`.
49814993

49824994
<li><p>Set <var>response</var>'s <a for=response>header list</a> to «
4983-
(`<code>Content-Length</code>`, <var>slicedLength</var>), (`<code>Content-Type</code>`,
4984-
<var>type</var>), (`<code>Content-Range</code>`, <var>contentRange</var>) ».
4995+
(`<code>Content-Length</code>`, <var>serializedSlicedLength</var>),
4996+
(`<code>Content-Type</code>`, <var>type</var>), (`<code>Content-Range</code>`,
4997+
<var>contentRange</var>) ».
49854998
</ol>
49864999

49875000
<li><p>Return <var>response</var>.

0 commit comments

Comments
 (0)