Skip to content

Commit d2004b0

Browse files
committed
Add set up the request/validate the response hooks to script fetching
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)
1 parent 1e43890 commit d2004b0

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

source

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84174,6 +84174,24 @@ interface <dfn>NavigatorOnLine</dfn> {
8417484174

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

84177+
<p>The various script-fetching algorithms below have two hooks that may be customized by their
84178+
callers:</p>
84179+
84180+
<ul>
84181+
84182+
<li><p><dfn data-x="fetching-scripts-set-up-request">set up the request</dfn>, which takes a
84183+
<span data-x="concept-request">request</span> object which it may modify before the algorithm
84184+
continues</p></li>
84185+
84186+
<li><p><dfn data-x="fetching-scripts-validate-response">validate the response</dfn>, which takes
84187+
a <span data-x="concept-response">response</span> object and must either accept or reject
84188+
it.</p></li>
84189+
84190+
</ul>
84191+
84192+
<p class="note"><cite>Service Workers</cite> is an example of a specification that runs these
84193+
algorithms with its own options for the hooks. <ref spec=SW></p>
84194+
8417784195
<p>To <dfn>fetch a classic script</dfn> for a <code>script</code> element <var>element</var>,
8417884196
given a <var>url</var>, a <var>CORS setting</var>, a <var>settings object</var>, and a
8417984197
<var>character encoding</var>, run these steps. The algorithm will asynchronously complete with
@@ -84189,6 +84207,9 @@ interface <dfn>NavigatorOnLine</dfn> {
8418984207
data-x="">script</code>", and its <span data-x="concept-request-destination">destination</span>
8419084208
to "<code data-x="">script</code>".</p></li>
8419184209

84210+
<li><p>If the caller specified custom steps to <span data-x="fetching-scripts-set-up-request">set
84211+
up the request</span>, perform them on <var>request</var>.</p></li>
84212+
8419284213
<!--FETCH-->
8419384214
<li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
8419484215

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

84230+
<li><p>If the caller specified custom steps to <span
84231+
data-x="fetching-scripts-validate-response">validate the response</span>, perform them on
84232+
<var>response</var>. If they reject the <var>response</var>, complete this algorithm with null,
84233+
and abort these steps.</p></li>
84234+
8420984235
<li><p>If <var>response</var>'s <span data-x="Content-Type">Content Type metadata</span>, if
8421084236
any, specifies a character encoding, and the user agent supports that encoding, then set
8421184237
<var>character encoding</var> to that encoding (ignoring the passed-in value).</p></li>
@@ -84247,6 +84273,9 @@ interface <dfn>NavigatorOnLine</dfn> {
8424784273
data-x="concept-request-credentials-mode">credentials mode</span> is "<code
8424884274
data-x="">same-origin</code>", and whose <span>use-URL-credentials flag</span> is set.</p></li>
8424984275

84276+
<li><p>If the caller specified custom steps to <span data-x="fetching-scripts-set-up-request">set
84277+
up the request</span>, perform them on <var>request</var>.</p></li>
84278+
8425084279
<!--FETCH-->
8425184280
<li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
8425284281

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

84291+
<li><p>If the caller specified custom steps to <span
84292+
data-x="fetching-scripts-validate-response">validate the response</span>, perform them on
84293+
<var>response</var>. If they reject the <var>response</var>, complete this algorithm with null,
84294+
and abort these steps.</p></li>
84295+
8426284296
<li><p>Let <var>source text</var> be the result of <span data-x="UTF-8 decode">UTF-8
8426384297
decoding</span> <var>response</var>'s <span data-x="concept-response-body">body</span>.</p></li>
8426484298

@@ -84277,7 +84311,11 @@ interface <dfn>NavigatorOnLine</dfn> {
8427784311
<li><p>If <var>ancestor list</var> is not given, let it be an empty list.</p></li>
8427884312

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

8428284320
<li><p>Return from this algorithm and run the following steps when <span data-x="fetch a single
8428384321
module script">fetching a single module script</span> asynchronously completes with
@@ -84341,6 +84379,11 @@ interface <dfn>NavigatorOnLine</dfn> {
8434184379
data-x="concept-module-script-credentials-mode">credentials mode</span>, <var>destination</var>,
8434284380
<var>module script</var>'s <span>settings object</span>, and <var>ancestor list</var>.</p>
8434384381

84382+
<p class="note">It is intentional that no custom <span
84383+
data-x="fetching-scripts-set-up-request">set up the request</span> or <span
84384+
data-x="fetching-scripts-validate-response">validate the response</span> steps are passed along
84385+
here. Those hooks only apply to the top-level fetch at the root of the module script tree.</p>
84386+
8434484387
<p>If any of the <span>fetch a module script tree</span> invocations asynchronously complete
8434584388
with null, the user agent may <span data-x="concept-fetch-terminate">terminate</span> any or
8434684389
all of the other fetches, and must then asynchronously complete this algorithm with null.</p>
@@ -84378,6 +84421,9 @@ interface <dfn>NavigatorOnLine</dfn> {
8437884421
mode</var>, and <span data-x="concept-request-client">client</span> is
8437984422
<var>settings object</var>.</p></li>
8438084423

84424+
<li><p>If the caller specified custom steps to <span data-x="fetching-scripts-set-up-request">set
84425+
up the request</span>, perform them on <var>request</var>.</p></li>
84426+
8438184427
<!--FETCH-->
8438284428
<li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
8438384429

@@ -84410,6 +84456,10 @@ interface <dfn>NavigatorOnLine</dfn> {
8441084456
classic script</span> does not include MIME type checking. In contrast, module scripts will
8441184457
fail to load if they are not of a correct MIME type.</p>
8441284458
</li>
84459+
84460+
<li><p>The caller specified custom steps to <span
84461+
data-x="fetching-scripts-validate-response">validate the response</span>, which when performed
84462+
on <var>response</var> reject it.</p></li>
8441384463
</ul>
8441484464
</li>
8441584465

0 commit comments

Comments
 (0)