@@ -4843,7 +4843,8 @@ steps:
48434843 <li><p> Set <var> request</var> 's
48444844 <a for=request>response tainting</a> to "<code> basic</code> ".
48454845
4846- <li><p> Return the result of running <a>scheme fetch</a> given <var> fetchParams</var> .
4846+ <li><p> Return the result of running <a>override fetch</a> given "<code> scheme-fetch</code> "
4847+ and <var> fetchParams</var> .
48474848 </ol>
48484849
48494850 <p class=note> HTML assigns any documents and workers created from <a for=/>URLs</a> whose
@@ -4862,7 +4863,8 @@ steps:
48624863
48634864 <li><p> Set <var> request</var> 's <a for=request>response tainting</a> to "<code> opaque</code> ".
48644865
4865- <li><p> Return the result of running <a>scheme fetch</a> given <var> fetchParams</var> .
4866+ <li><p> Return the result of running <a>override fetch</a> given "<code> scheme-fetch</code> " and
4867+ <var> fetchParams</var> .
48664868 <!-- file URLs end up here as they are not same-origin typically. -->
48674869 </ol>
48684870
@@ -4881,8 +4883,8 @@ steps:
48814883 <a for=request>response tainting</a> to
48824884 "<code> cors</code> ".
48834885
4884- <li><p> Let <var> corsWithPreflightResponse</var> be the result of running <a>HTTP fetch</a>
4885- given < var> fetchParams</var> and true.
4886+ <li><p> Let <var> corsWithPreflightResponse</var> be the result of running <a>override fetch</a>
4887+ given " <code> http-fetch </code> ", < var> fetchParams</var> , and true.
48864888
48874889 <li><p> If <var> corsWithPreflightResponse</var> is a <a>network error</a> , then
48884890 <a>clear cache entries</a> using <var> request</var> .
@@ -4897,7 +4899,8 @@ steps:
48974899 <a for=request>response tainting</a> to
48984900 "<code> cors</code> ".
48994901
4900- <li><p> Return the result of running <a>HTTP fetch</a> given <var> fetchParams</var> .
4902+ <li><p> Return the result of running <a>override fetch</a> given "<code> http-fetch</code> " and
4903+ <var> fetchParams</var> .
49014904 </ol>
49024905 </dl>
49034906
@@ -5218,6 +5221,96 @@ steps:
52185221</div>
52195222
52205223
5224+ <h3 id=override-fetch>Override fetch</h3>
5225+
5226+ <div algorithm>
5227+ <p> To <dfn id=concept-override-fetch>override fetch</dfn> , given "<code> scheme-fetch</code> " or
5228+ "<code> http-fetch</code> " <var> type</var> , a <a for=/>fetch params</a> <var> fetchParams</var> , and
5229+ an optional boolean <var> makeCORSPreflight</var> (default false):
5230+
5231+ <ol>
5232+ <li><p> Let <var> request</var> be <var> fetchParams</var> ' <a for="fetch params">request</a> .
5233+
5234+ <li><p> Let <var> response</var> be the result of executing
5235+ <a>potentially override response for a request</a> on <var> request</var> .
5236+
5237+ <li><p> If <var> response</var> is non-null, then return <var> response</var> .
5238+
5239+ <li>
5240+ <p> Switch on <var> type</var> and run the associated step:
5241+
5242+ <dl class=switch>
5243+ <dt> "<code> scheme fetch</code> "
5244+ <dd><p> Set <var> response</var> be the result of running <a>scheme fetch</a> given
5245+ <var> fetchParams</var> .
5246+
5247+ <dt> "<code> HTTP fetch</code> "
5248+ <dd><p> Set <var> response</var> be the result of running <a>HTTP fetch</a> given
5249+ <var> fetchParams</var> and <var> makeCORSPreflight</var> .
5250+ </dl>
5251+
5252+ <li><p> Return <var> response</var> .
5253+ </ol>
5254+ </div>
5255+
5256+ <div algorithm>
5257+ <p> The <dfn>potentially override response for a request</dfn> algorithm takes a <a for=/>request</a>
5258+ <var> request</var> , and returns either a <a for=/>response</a> or null. Its behavior is
5259+ <a>implementation-defined</a> , allowing user agents to intervene on the <a for=/>request</a> by
5260+ returning a response directly, or allowing the request to proceed by returning null.
5261+
5262+ <p> By default, the algorithm has the following trivial implementation:
5263+
5264+ <ol>
5265+ <li><p> Return null.
5266+ </ol>
5267+
5268+ <div class=note>
5269+ <p> User agents will generally override this default implementation with a somewhat more complex
5270+ set of behaviors. For example, a user agent might decide that its users' safety is best preserved
5271+ by generally blocking requests to `https://unsafe.example/`, while synthesizing a shim for the
5272+ widely-used resource `https://unsafe.example/widget.js` to avoid breakage. That implementation
5273+ might look like the following:
5274+
5275+ <ol>
5276+ <li><p> If <var> request</var> 's <a for=request>current url</a>' s <a for=url>host</a> 's
5277+ <a for=host>registrable domain</a> is "<code> unsafe.example</code> ":
5278+
5279+ <ol>
5280+ <li><p> If <var> request</var> 's <a for=request>current url</a>' s <a for=url>path</a> is
5281+ « "<code> widget.js</code> " »:
5282+
5283+ <ol>
5284+ <li><p> Let <var> body</var> be [<em> insert a byte sequence representing the shimmed
5285+ content here</em> ].
5286+
5287+ <li><p> Return a new <a for=/>response</a> with the following properties:
5288+
5289+ <dl>
5290+ <dt> <a for=response>type</a>
5291+ <dd> "<code> cors</code> "
5292+
5293+ <dt> <a for=response>status</a>
5294+ <dd> 200</dd>
5295+
5296+ <dt> ...
5297+ <dd> ...
5298+
5299+ <dt> <a for=response>body</a>
5300+ <dd> The result of getting <var> body</var> <a>as a body</a> .
5301+ </dl>
5302+ </ol>
5303+
5304+ <li><p> Return a <a>network error</a> .
5305+ </ol>
5306+
5307+ <li><p> Return null.
5308+ </ol>
5309+ </div>
5310+
5311+ </div>
5312+
5313+
52215314<h3 id=scheme-fetch oldids=basic-fetch>Scheme fetch</h3>
52225315
52235316<div algorithm>
0 commit comments