Skip to content

Commit dc83dde

Browse files
jakearchibaldannevk
authored andcommitted
Specifying how media elements make and validate range requests
1 parent 88de068 commit dc83dde

File tree

1 file changed

+142
-10
lines changed

1 file changed

+142
-10
lines changed

source

Lines changed: 142 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,6 +2496,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
24962496
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#http-cors-protocol">CORS protocol</dfn></li>
24972497
<li><dfn data-x="default-user-agent-value" data-x-href="https://fetch.spec.whatwg.org/#default-user-agent-value">default `<code>User-Agent</code>` value</dfn></li>
24982498
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#concept-header-extract-mime-type">extract a MIME type</dfn></li>
2499+
<li><dfn data-x="extract-header-list-values" data-x-href="https://fetch.spec.whatwg.org/#extract-header-list-values">extract header list values</dfn></li>
24992500
<li><dfn data-x="concept-fetch" data-x-href="https://fetch.spec.whatwg.org/#concept-fetch">fetch</dfn></li>
25002501
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#concept-http-redirect-fetch">HTTP-redirect fetch</dfn></li>
25012502
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#ok-status">ok status</dfn></li>
@@ -2563,6 +2564,16 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
25632564
<li><dfn data-x="concept-request-parser-metadata" data-x-href="https://fetch.spec.whatwg.org/#concept-request-parser-metadata">parser metadata</dfn></li>
25642565
<li><dfn data-x="concept-request-reload-navigation-flag" data-x-href="https://fetch.spec.whatwg.org/#concept-request-reload-navigation-flag">reload-navigation flag</dfn></li>
25652566
<li><dfn data-x="concept-request-history-navigation-flag" data-x-href="https://fetch.spec.whatwg.org/#concept-request-history-navigation-flag">history-navigation flag</dfn></li>
2567+
<li><dfn data-x="concept-request-add-range-header" data-x-href="https://fetch.spec.whatwg.org/#concept-request-add-range-header">add a range header</dfn> algorithm</li>
2568+
</ul>
2569+
</li>
2570+
<li>
2571+
<dfn data-x="concept-header-list"
2572+
data-x-href="https://fetch.spec.whatwg.org/#concept-header-list">header list</dfn> and its
2573+
associated:
2574+
<ul class="brief">
2575+
<li><dfn data-x="concept-header-list-allow-privileged-headers" data-x-href="https://fetch.spec.whatwg.org/#concept-header-list-allow-privileged-headers">allow privileged headers flag</dfn></li>
2576+
<li><dfn data-x="concept-header-list-append" data-x-href="https://fetch.spec.whatwg.org/#concept-header-list-append">append</dfn> algorithm</li>
25662577
</ul>
25672578
</li>
25682579
</ul>
@@ -32818,6 +32829,25 @@ interface <dfn>HTMLMediaElement</dfn> : <span>HTMLElement</span> {
3281832829

3281932830
</p>
3282032831

32832+
<p>A <span>media resource</span> has a <dfn
32833+
data-x="concept-media-uses-rewritten-requests-flag">uses rewritten requests flag</dfn>, which is
32834+
initially unset.</p>
32835+
32836+
<p class="note">The <span data-x="concept-media-uses-rewritten-requests-flag">uses rewritten
32837+
requests flag</span> is used to track <span>media resource</span>s that use responses that didn't
32838+
originate from their request URL, which is possible via a service worker. The aim is to prevent
32839+
developers from mixing <span>CORS-cross-origin</span> responses from different sources in a way
32840+
that could expose data through the media's duration, width, or height.</p>
32841+
32842+
<p>A <span>media resource</span> has a <dfn
32843+
data-x="concept-media-resource-uses-opaque-response-flag">uses opaque response flag</dfn>, which
32844+
is initially unset.</p>
32845+
32846+
<p class="note">The <span data-x="concept-media-resource-uses-opaque-response-flag">uses opaque
32847+
response flag</span> affects whether subtitles referenced in the <span>media data</span> are
32848+
exposed in the API and, for <code>video</code> elements, whether a <code>canvas</code> gets
32849+
tainted when the video is drawn on it.</p>
32850+
3282132851
<p>A <span>media resource</span> can have multiple audio and video tracks. For the purposes of a
3282232852
<span>media element</span>, the video data of the <span>media resource</span> is only that of the
3282332853
currently selected track (if any) as given by the element's <code
@@ -33708,11 +33738,20 @@ interface <dfn>MediaError</dfn> {
3370833738

3370933739
<!--FETCH--><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.
3371033740

33711-
<p>The <var>response</var>'s <span>unsafe response</span> obtained in this fashion, if any,
33712-
contains the <span>media data</span>. It can be <span>CORS-same-origin</span> or
33713-
<span>CORS-cross-origin</span>; this affects whether subtitles referenced in the <span>media
33714-
data</span> are exposed in the API and, for <code>video</code> elements, whether a
33715-
<code>canvas</code> gets tainted when the video is drawn on it.</p>
33741+
<p>Let <var>responseUrlList</var> be <var>response</var>'s <span
33742+
data-x="concept-response-url-list">url list</span></p>
33743+
33744+
<p>If <var>responseUrlList</var>[0] does not <span data-x="list contains">exist</span>, or
33745+
<var>responseUrlList</var>[0] does not equal <var>request</var>'s <span
33746+
data-x="concept-request-url">url</span>, set <var>current media resource</var>'s <span
33747+
data-x="concept-media-uses-rewritten-requests-flag">uses rewritten requests flag</span>.</p>
33748+
33749+
<p class="note">We test the first entry of the <span data-x="concept-response-url-list">url
33750+
list</span> since that reveals if the service worker "rewrote" the request to another URL.</p>
33751+
33752+
<p>If the <var>response</var> is <span>CORS-cross-origin</span>, set the <var>current media
33753+
resource</var>'s <span data-x="concept-media-resource-uses-opaque-response-flag">uses opaque
33754+
response flag</span>.
3371633755

3371733756
<p>The <dfn>stall timeout</dfn> is an <span>implementation-defined</span> length of time,
3371833757
which should be about three seconds. When a <span>media element</span> that is actively
@@ -33754,11 +33793,17 @@ interface <dfn>MediaError</dfn> {
3375433793
element's <span>delaying-the-load-event flag</span> to false. This stops <span data-x="delay
3375533794
the load event">delaying the load event</span>.</p>
3375633795

33757-
<p>The user agent may use whatever means necessary to fetch the resource (within the constraints
33758-
put forward by this and other specifications); for example, reconnecting to the server in the
33759-
face of network errors, using HTTP range retrieval requests, or switching to a streaming
33760-
protocol. The user agent must consider a resource erroneous only if it has given up trying to
33761-
fetch it.</p>
33796+
<p>The user agent may go on to use whatever means necessary to fetch the resource (within
33797+
the constraints put forward by this and other specifications); for example, reconnecting to
33798+
the server in the face of network errors, or switching to a streaming protocol. The user
33799+
agent must consider a resource erroneous only if it has given up trying to fetch it.</p>
33800+
33801+
<p>The user agent may use the <span data-x="concept-media-ranged-fetch-steps">ranged fetch
33802+
steps</span> to perform HTTP range retrieval requests for a given start and (optional) end
33803+
range. Through its knowledge of container formats, the user agent may issue a ranged request
33804+
to gather metadata it knows to be at the end of the resource. Or, if the media is seeked,
33805+
the browser may use metadata to convert a temporal range to a byte range and make a ranged
33806+
request.</p>
3376233807

3376333808
<p>To determine the format of the <span>media resource</span>, the user agent must use the
3376433809
<span data-x="Content-Type sniffing: video">rules for sniffing audio and video specifically</span>.</p>
@@ -33792,6 +33837,93 @@ interface <dfn>MediaError</dfn> {
3379233837
in this situation, once <span data-x="ended playback">playback has ended</span>, the user agent
3379333838
will end up firing a <code data-x="event-media-suspend">suspend</code> event, as described
3379433839
earlier.</p>
33840+
33841+
<p>The <dfn data-x="concept-media-ranged-fetch-steps">ranged fetch steps</dfn> with a
33842+
<var>start</var> and optional <var>end</var> are the following steps:</p>
33843+
33844+
<ol>
33845+
<li><p>Let <var>request</var> be the result of <span
33846+
data-x="create a potential-CORS request">creating a potential-CORS request</span> given
33847+
<var>URL record</var>, "<code data-x="">media</code>", and the <var>crossorigin attribute
33848+
value</var>.</p></li>
33849+
33850+
<li><p>Set <var>request</var>'s <span data-x="concept-request-client">client</span> to the
33851+
<span>media element</span>'s <span>node document</span>'s <code>Window</code> object's
33852+
<span>environment settings object</span></p></li>
33853+
33854+
<li><p>Set <var>request</var>'s <span data-x="concept-request-type">type</span> to "<code
33855+
data-x="">audio</code>" if the <span>media element</span> is an <code>audio</code> element
33856+
and to "<code data-x="">video</code>" otherwise.</p></li>
33857+
33858+
<li><p><span data-x="concept-request-add-range-header">Add a range header</span> to
33859+
<var>request</var> with <var>start</var> and if provided, <var>end</var>.
33860+
33861+
<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
33862+
33863+
<li><p>If the <var>response</var> is a <span>network error</span>, return
33864+
<var>response</var>.</p></li>
33865+
33866+
<li><p>Let <var>requestRewritten</var> be false.</p></li>
33867+
33868+
<li><p>Let <var>responseUrlList</var> be <var>response</var>'s <span
33869+
data-x="concept-response-url-list">url list</span></p></li>
33870+
33871+
<li><p>If <var>responseUrlList</var>[0] does not <span data-x="list
33872+
contains">exist</span>, or <var>responseUrlList</var>[0] does not equal
33873+
<var>request</var>'s <span data-x="concept-request-url">url</span>, set
33874+
<var>requestRewritten</var> to true</p></li>
33875+
33876+
<li>
33877+
<p>If the <var>response</var> is <span>CORS-cross-origin</span>, or the <var>current
33878+
media resource</var>'s <span
33879+
data-x="concept-media-resource-uses-opaque-response-flag">uses opaque response
33880+
flag</span> is set, then:</p>
33881+
33882+
<ol>
33883+
<li><p>If <var>requestRewritten</var> is true, or <var>current media resource</var>'s
33884+
<span data-x="concept-media-uses-rewritten-requests-flag">uses rewritten requests
33885+
flag</span> is set, then return a <span>network error</span>.</p></li>
33886+
</ol>
33887+
</li>
33888+
33889+
<li><p>If <var>response</var>'s <span data-x="concept-response-status">status</span> is
33890+
not <code data-x="">200</code> or <code data-x="">206</code>, return a <span>network
33891+
error</span>.</p></li>
33892+
33893+
<li>
33894+
<p>If <var>response</var>'s <span data-x="concept-response-status">status</span> is
33895+
<code data-x="">206</code>, then:</p>
33896+
33897+
<ol>
33898+
<li><p>Let <var>range</var> be the result of <span
33899+
data-x="extract-header-list-values">extracting</span> `<code
33900+
data-x="">Content-Range</code>` from <var>response</var>'s <span
33901+
data-x="concept-request-header-list">header list</span>.</p></li>
33902+
33903+
<li><p>If <var>range</var>'s <a
33904+
href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16">first-byte-pos</a>
33905+
doesn't equal <var>start</var>, return a <span>network error</span>.</p></li>
33906+
</ol>
33907+
</li>
33908+
33909+
<li><p>If <var>requestRewritten</var> is true, set <var>current media resource</var>'s
33910+
<span data-x="concept-media-uses-rewritten-requests-flag">uses rewritten requests
33911+
flag</span>.</p></li>
33912+
33913+
<li><p>If the <var>response</var> is <span>CORS-cross-origin</span>, set the <var>current
33914+
media resource</var>'s <span
33915+
data-x="concept-media-resource-uses-opaque-response-flag">uses opaque data flag</span>.</p></li>
33916+
33917+
<li>
33918+
<p>Return <var>response</var>.</p>
33919+
33920+
<p class="note">How the browser consumes responses for various media types isn't covered
33921+
by this spec. However, the browser is encouraged to accept an HTTP 200 response even if
33922+
it requested a range. It could terminate fetches that are (or become) redundant, e.g. if
33923+
the returned range is already covered by a previous or in-flight response, or the media
33924+
is seeked as such that active fetches are unlikely to be useful.</p>
33925+
</li>
33926+
</ol>
3379533927
</li>
3379633928
</ol>
3379733929
</dd>

0 commit comments

Comments
 (0)