Skip to content

Commit

Permalink
Add set up the request/validate the response hooks to script fetching
Browse files Browse the repository at this point in the history
This allows more complicated callers, like service workers, to
customize script fetching as necessary. See [1], and in particular [2].

[1]: w3c/ServiceWorker#831
[2]: w3c/ServiceWorker#831 (comment)
  • Loading branch information
domenic authored and annevk committed Feb 29, 2016
1 parent 4e22a3e commit 33ef23a
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion source
Original file line number Diff line number Diff line change
Expand Up @@ -84869,6 +84869,23 @@ interface <dfn>NavigatorOnLine</dfn> {

<h5 id="fetching-scripts">Fetching scripts</h5>

<p>The various script-fetching algorithms below have two hooks that may be customized by their
callers:</p>

<ul>

<li><p><dfn data-x="fetching-scripts-set-up-request">Set up the request</dfn>, which takes a
<span data-x="concept-request">request</span> which it may modify before the algorithm
continues</p></li>

<li><p><dfn data-x="fetching-scripts-validate-response">Validate the response</dfn>, which takes
a <span data-x="concept-response">response</span> and must either return true or false</p></li>

</ul>

<p class="note"><cite>Service Workers</cite> is an example of a specification that runs these
algorithms with its own options for the hooks. <ref spec=SW></p>

<p>To <dfn>fetch a classic script</dfn> for a <code>script</code> element <var>element</var>,
given a <var>url</var>, a <var>CORS setting</var>, a <var>settings object</var>, and a
<var>character encoding</var>, run these steps. The algorithm will asynchronously complete with
Expand All @@ -84884,6 +84901,9 @@ interface <dfn>NavigatorOnLine</dfn> {
data-x="">script</code>", and its <span data-x="concept-request-destination">destination</span>
to "<code data-x="">script</code>".</p></li>

<li><p>If the caller specified custom steps to <span data-x="fetching-scripts-set-up-request">set
up the request</span>, perform them on <var>request</var>.</p></li>

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

Expand All @@ -84901,6 +84921,11 @@ interface <dfn>NavigatorOnLine</dfn> {
data-x="concept-response-status">status</span> is not an <span>ok status</span>, asynchronously
complete this algorithm with null, and abort these steps.</p></li>

<li><p>If the caller specified custom steps to <span
data-x="fetching-scripts-validate-response">validate the response</span>, perform them on
<var>response</var>. If they return false, complete this algorithm with null, and abort these
steps.</p></li>

<li><p>If <var>response</var>'s <span data-x="Content-Type">Content Type metadata</span>, if
any, specifies a character encoding, and the user agent supports that encoding, then set
<var>character encoding</var> to that encoding (ignoring the passed-in value).</p></li>
Expand Down Expand Up @@ -84942,6 +84967,9 @@ interface <dfn>NavigatorOnLine</dfn> {
data-x="concept-request-credentials-mode">credentials mode</span> is "<code
data-x="">same-origin</code>", and whose <span>use-URL-credentials flag</span> is set.</p></li>

<li><p>If the caller specified custom steps to <span data-x="fetching-scripts-set-up-request">set
up the request</span>, perform them on <var>request</var>.</p></li>

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

Expand All @@ -84954,6 +84982,11 @@ interface <dfn>NavigatorOnLine</dfn> {
data-x="concept-response-status">status</span> is not an <span>ok status</span>, asynchronously
complete this algorithm with null, and abort these steps.</p></li>

<li><p>If the caller specified custom steps to <span
data-x="fetching-scripts-validate-response">validate the response</span>, perform them on
<var>response</var>. If they return false, complete this algorithm with null, and abort these
steps.</p></li>

<li><p>Let <var>source text</var> be the result of <span data-x="UTF-8 decode">UTF-8
decoding</span> <var>response</var>'s <span data-x="concept-response-body">body</span>.</p></li>

Expand All @@ -84972,7 +85005,11 @@ interface <dfn>NavigatorOnLine</dfn> {
<li><p>If <var>ancestor list</var> is not given, let it be an empty list.</p></li>

<li><p><span>Fetch a single module script</span> given <var>url</var>, <var>credentials
mode</var>, <var>destination</var>, and <var>settings object</var>.</p>
mode</var>, <var>destination</var>, and <var>settings object</var>. If the caller of this
algorithm specified custom <span data-x="fetching-scripts-set-up-request">set up the
request</span> or <span data-x="fetching-scripts-validate-response">validate the response</span>
steps, pass those along while <span data-x="fetch a single module script">fetching a single
module script</span>.</p>

<li><p>Return from this algorithm and run the following steps when <span data-x="fetch a single
module script">fetching a single module script</span> asynchronously completes with
Expand All @@ -84991,6 +85028,12 @@ interface <dfn>NavigatorOnLine</dfn> {
asynchronously complete this algorithm with <var>descendants result</var>.</p></li>
</ol>

<hr>

<p>The following algorithms are used when <span data-x="fetch a module script tree">fetching a
module script tree</span>, and are not meant to be used directly by other specifications (or by
other parts of this specification).</p>

<p>To <dfn>fetch the descendants of a module script</dfn> <var>module script</var>, given a
<var>destination</var> and an <var>ancestor list</var>, run these steps. The algorithm will
asynchronously complete with either null (on failure) or with <var>module script</var> (on
Expand Down Expand Up @@ -85036,6 +85079,11 @@ interface <dfn>NavigatorOnLine</dfn> {
data-x="concept-module-script-credentials-mode">credentials mode</span>, <var>destination</var>,
<var>module script</var>'s <span>settings object</span>, and <var>ancestor list</var>.</p>

<p class="note">It is intentional that no custom <span
data-x="fetching-scripts-set-up-request">set up the request</span> or <span
data-x="fetching-scripts-validate-response">validate the response</span> steps are passed along
here. Those hooks only apply to the top-level fetch at the root of the module script tree.</p>

<p>If any of the <span>fetch a module script tree</span> invocations asynchronously complete
with null, the user agent may <span data-x="concept-fetch-terminate">terminate</span> any or
all of the other fetches, and must then asynchronously complete this algorithm with null.</p>
Expand Down Expand Up @@ -85073,6 +85121,9 @@ interface <dfn>NavigatorOnLine</dfn> {
mode</var>, and <span data-x="concept-request-client">client</span> is
<var>settings object</var>.</p></li>

<li><p>If the caller specified custom steps to <span data-x="fetching-scripts-set-up-request">set
up the request</span>, perform them on <var>request</var>.</p></li>

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

Expand Down Expand Up @@ -85105,6 +85156,10 @@ interface <dfn>NavigatorOnLine</dfn> {
classic script</span> does not include MIME type checking. In contrast, module scripts will
fail to load if they are not of a correct MIME type.</p>
</li>

<li><p>The caller specified custom steps to <span
data-x="fetching-scripts-validate-response">validate the response</span>, which when performed
on <var>response</var> return false.</p></li>
</ul>
</li>

Expand Down

0 comments on commit 33ef23a

Please sign in to comment.