Skip to content

Commit ddaaef9

Browse files
committedMay 8, 2023
Define preconnect and dns-prefetch with CSP
See whatwg/html#9035
1 parent aaada1f commit ddaaef9

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed
 

‎fetch.bs

+73-1
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,78 @@ details of reused connections are not exposed and time values are coarsened.
30273027
</div>
30283028

30293029

3030+
<h3 id=preemptive-connection-operations>Preemptive connection operations</h3>
3031+
3032+
<div algorithm="preemmptively-obtain-a-connection">
3033+
<p>To <dfn export>preemptively obtain a connection</dfn>, given an
3034+
<a>environment settings object</a> <var>environment</var>, a <a for=/>URL</a> <var>url</var>, and a
3035+
boolean <var>credentials</var>, run these steps:
3036+
3037+
<ol>
3038+
<li><p>Let <var>key</var> be the result of <a for=/>determining the network partition key</a> given
3039+
<var>environment</var>.
3040+
3041+
<li>
3042+
<p><a>Check CSP for preemptive operation</a> with <var>environment</var> and <var>url</var>. If
3043+
that returns <b>allowed</b>, <a>Obtain a connection</a> with <var>key</var>, <var>url</var> and
3044+
<var>credentials</var>.
3045+
3046+
<p class=note>This connection is obtained but not used directly. It will remain in the
3047+
<a>connection pool</a> for subsequent use.
3048+
3049+
<p class=note>The user agent should attempt to initiate a preconnect and perform the full
3050+
connection handshake (DNS+TCP for HTTP, and DNS+TCP+TLS for HTTPS origins) whenever possible, but
3051+
is allowed to elect to perform a partial handshake (DNS only for HTTP, and DNS or DNS+TCP for
3052+
HTTPS origins), or skip it entirely, due to resource constraints or other reasons.</p>
3053+
3054+
<p class=note>The optimal number of connections per origin is dependent on the negotiated
3055+
protocol, users current connectivity profile, available device resources, global connection
3056+
limits, and other context specific variables. As a result, the decision for how many connections
3057+
should be opened is deferred to the user agent.</p>
3058+
</ol>
3059+
</div>
3060+
3061+
<div algorithm="preemmptively-resolve-an-origin">
3062+
<p>To <dfn export>preemptively resolve an origin</dfn>, given an
3063+
<a>environment settings object</a> <var>environment</var> and a <a for=/>URL</a> <var>url</var>, run
3064+
these steps:
3065+
3066+
<ol>
3067+
<li><p>Let <var>key</var> be the result of <a for=/>determining the network partition key</a> given
3068+
<var>environment</var>.
3069+
3070+
<li><p><a>Check CSP for preemptive operation</a> with <var>environment</var> and <var>url</var>. If
3071+
that returns <b>blocked</b>, return.
3072+
3073+
<li><p>Let <var>proxies</var> be the result of finding proxies for <var>url</var> in an
3074+
<a>implementation-defined</a> manner.
3075+
3076+
<li>
3077+
<p>If there <var>proxies</var> is <a for=list>empty</a>, or if <var>proxies</var>
3078+
<a for=list>contains</a> "<code>DIRECT</code>", then <a>resolve an origin</a> given <var>key</var>
3079+
and <var>url</var>'s <a for=url>origin</a>.
3080+
3081+
<p class=note>As the results of this algorithm can be cached, future fetches could be faster.
3082+
</ol>
3083+
</div>
3084+
3085+
<div algorithm="check-preemptive-operation-csp">
3086+
<p>To <dfn>Check CSP for preemptive operation</dfn>, given an
3087+
<a>environment settings object</a> <var>environment</var>, and a <a for=/>URL</a> <var>url</var>,
3088+
run these steps:
3089+
3090+
<ol>
3091+
<li><p>Let <var>request</var> be a <a for=/>request</a> whose <a for=request>URL</a> is
3092+
<var>url</var>, <a for=request>initiator</a> is "<code>prefetch</code>", and whose
3093+
<a for=request>client</a> is <var>environment</var>.
3094+
3095+
<li><p>Return the result of running <a>should request be blocked by Content Security Policy?</a>
3096+
given <var>request</var>.
3097+
3098+
</ol>
3099+
</div>
3100+
3101+
30303102
<h3 id=network-partition-keys>Network partition keys</h3>
30313103

30323104
<p>A <dfn>network partition key</dfn> is a tuple consisting of a <a for=/>site</a> and null or
@@ -8720,7 +8792,7 @@ to discuss. [[CSP]]
87208792
<a>environment settings object</a> you're operating in. Web-exposed APIs are generally defined with
87218793
Web IDL, for which every object that implements an <a>interface</a> has a
87228794
<a>relevant settings object</a> you can use. For example, a <a for=/>request</a> associated with an
8723-
<a for=/>element</a> would set the <a for=/>request</a>'s <a for=request>client</a> to the element's
8795+
{{Element}} would set the <a for=/>request</a>'s <a for=request>client</a> to the element's
87248796
<a>node document</a>'s <a>relevant settings object</a>. All features that are directly web-exposed
87258797
by JavaScript, HTML, CSS, or other {{Document}} subresources should have a
87268798
<a for=request>client</a>.

0 commit comments

Comments
 (0)
Please sign in to comment.