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 committed Feb 26, 2016
1 parent 1e43890 commit d2004b0
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion source
Original file line number Diff line number Diff line change
Expand Up @@ -84174,6 +84174,24 @@ 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> object 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> object and must either accept or reject
it.</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 @@ -84189,6 +84207,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 @@ -84206,6 +84227,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 reject the <var>response</var>, 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 @@ -84247,6 +84273,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 @@ -84259,6 +84288,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 reject the <var>response</var>, 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 @@ -84277,7 +84311,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 Down Expand Up @@ -84341,6 +84379,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 @@ -84378,6 +84421,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 @@ -84410,6 +84456,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> reject it.</p></li>
</ul>
</li>

Expand Down

0 comments on commit d2004b0

Please sign in to comment.