Skip to content

Commit 6f37b51

Browse files
Allow particular Range header values without a CORS preflight
The allowed format aligns with the values the browser uses when requesting media and resuming downloads. Tests: web-platform-tests/wpt#31058. Fixes #1310.
1 parent 8659a25 commit 6f37b51

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

fetch.bs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ production as
777777
<ol>
778778
<li><p>Let <var>value</var> be <var>header</var>'s <a for=header>value</a>.
779779

780+
<li><p>If <var>value</var>'s <a for="byte sequence">length</a> is greater than 128, then return
781+
false.
782+
780783
<li>
781784
<p><a>Byte-lowercase</a> <var>header</var>'s <a for=header>name</a> and switch on the result:
782785

@@ -829,13 +832,13 @@ fetch("https://victim.example/naïve-endpoint", {
829832
</code></pre>
830833
</div>
831834

835+
<dt>`<code>range</code>`
836+
<dd><p>If <var>value</var> is not a <a>simple range header value</a>, then return false.
837+
832838
<dt>Otherwise
833839
<dd><p>Return false.
834840
</dl>
835841

836-
<li><p>If <var>value</var>'s <a for="byte sequence">length</a> is greater than 128, then return
837-
false.
838-
839842
<li><p>Return true.
840843
</ol>
841844

@@ -1045,6 +1048,46 @@ run these steps:
10451048
<li><p>Return <var>values</var>.
10461049
</ol>
10471050

1051+
<p>To determine if a <a>byte sequence</a> <var>value</var> is a
1052+
<dfn>simple range header value</dfn>, perform the following steps. They return a <a>boolean</a>.
1053+
1054+
<ol>
1055+
<li><p>Let <var>data</var> be the <a>isomorphic decoding</a> of <var>value</var>.
1056+
1057+
<li><p>If <var>data</var> does not <a for=string>start with</a> "<code>bytes=</code>", then return
1058+
false.
1059+
1060+
<li><p>Let <var>position</var> be a <a>position variable</a> for <var>data</var>, initially
1061+
pointing at the 6th <a>code point</a> of <var>data</var>.
1062+
1063+
<li><p>Let <var>rangeStart</var> be the result of <a>collecting a sequence of code points</a> that
1064+
are <a>ASCII digits</a>, from <var>data</var> given <var>position</var>.
1065+
1066+
<li><p>If the <a>code point</a> at <var>position</var> within <var>data</var> is not U+002D (-),
1067+
then return false.
1068+
1069+
<li><p>Advance <var>position</var> by 1.
1070+
1071+
<li><p>Let <var>rangeEnd</var> be the result of <a>collecting a sequence of code points</a> that
1072+
are <a>ASCII digits</a>, from <var>data</var> given <var>position</var>.
1073+
1074+
<li><p>If <var>position</var> is not past the end of <var>data</var>, then return false.
1075+
1076+
<li>
1077+
<p>If <var>rangeEnd</var>'s <a for=string>length</a> is 0, then return true.
1078+
1079+
<p class="note">The range end can be omitted, e.g., `<code>bytes 0-</code>` is valid.
1080+
1081+
<li><p>If <var>rangeStart</var>, interpreted as decimal number, is greater than
1082+
<var>rangeEnd</var>, interpreted as decimal number, then return false.
1083+
1084+
<li><p>Return true.
1085+
</ol>
1086+
1087+
<p class="note">A <a>simple range header value</a> is a subset of allowed range header values, but
1088+
it is the most common form used by user agents when requesting media or resuming downloads. This
1089+
format of range header value can be set using <a>add a range header</a>.
1090+
10481091
<hr>
10491092

10501093
<p>A <dfn id=default-user-agent-value export>default `<code>User-Agent</code>` value</dfn> is a
@@ -1854,7 +1897,10 @@ is to return the result of <a>serializing a request origin</a> with <var>request
18541897
<var>last</var>, run these steps:
18551898

18561899
<ol>
1857-
<li><p>Let <var>rangeValue</var> be `<code>bytes </code>`.
1900+
<li><p>Assert: <var>last</var> is not given, or <var>first</var> is less than or equal to
1901+
<var>last</var>.
1902+
1903+
<li><p>Let <var>rangeValue</var> be `<code>bytes=</code>`.
18581904

18591905
<li><p><a lt="serialize an integer">Serialize</a> and <a>isomorphic encode</a> <var>first</var>,
18601906
and append the result to <var>rangeValue</var>.

0 commit comments

Comments
 (0)