Skip to content

Commit 965aad8

Browse files
committed
Define preconnect and dns-prefetch with CSP
See whatwg/html#9035
1 parent 1065777 commit 965aad8

File tree

1 file changed

+73
-32
lines changed

1 file changed

+73
-32
lines changed

fetch.bs

+73-32
Original file line numberDiff line numberDiff line change
@@ -2909,37 +2909,6 @@ reused across <a>connections</a> whose <a for=connection>credentials</a> are fal
29092909
<a>connections</a> whose <a for=connection>credentials</a> are true.
29102910
</div>
29112911

2912-
<div algorithm="preemmptively-obtain-a-connection">
2913-
<p>To <dfn export>preemptively obtain a connection</dfn>, given an
2914-
<a>environment settings object</a> <var>environment</var>, a <a for=/>URL</a> <var>url</var>, and a
2915-
boolean <var>credentials</var>, run these steps:
2916-
2917-
<ol>
2918-
<li><p>Let <var>key</var> be the result of <a for=/>determining the network partition key</a> given
2919-
<var>environment</var>.
2920-
2921-
<li><p><a>Check resource hint CSP</a> with <var>environment</var> and <var>url</var>. If that
2922-
returns <b>allowed</b>, <a>Obtain a connection</a> with <var>key</var>, <var>url</var> and
2923-
<var>credentials</var>.
2924-
</ol>
2925-
</div>
2926-
2927-
<div algorithm="check-resource-hint-csp">
2928-
<p>To <dfn export>Check resource hint CSP</dfn>, given an
2929-
<a>environment settings object</a> <var>environment</var>, and a <a for=/>URL</a> <var>url</var>,
2930-
run these steps:
2931-
2932-
<ol>
2933-
<li><p>Let <var>request</var> be a <a for=/>request</a> whose <a for=request>URL</a> is
2934-
<var>url</var>, <a for=request>initiator</a> is "<code>prefetch</code>", and whose
2935-
<a for=request>client</a> is <var>environment</var>.
2936-
2937-
<li><p>Return the result of running <a>should request be blocked by Content Security Policy?</a>
2938-
given <var>request</var>.
2939-
2940-
</ol>
2941-
</div>
2942-
29432912
<hr>
29442913

29452914
<div algorithm>
@@ -3053,6 +3022,78 @@ details of reused connections are not exposed and time values are coarsened.
30533022
</div>
30543023

30553024

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

30583099
<p>A <dfn>network partition key</dfn> is a tuple consisting of a <a for=/>site</a> and null or
@@ -8719,7 +8760,7 @@ to discuss. [[CSP]]
87198760
<a>environment settings object</a> you're operating in. Web-exposed APIs are generally defined with
87208761
Web IDL, for which every object that implements an <a>interface</a> has a
87218762
<a>relevant settings object</a> you can use. For example, a <a for=/>request</a> associated with an
8722-
<a for=/>element</a> would set the <a for=/>request</a>'s <a for=request>client</a> to the element's
8763+
{{Element}} would set the <a for=/>request</a>'s <a for=request>client</a> to the element's
87238764
<a>node document</a>'s <a>relevant settings object</a>. All features that are directly web-exposed
87248765
by JavaScript, HTML, CSS, or other {{Document}} subresources should have a
87258766
<a for=request>client</a>.

0 commit comments

Comments
 (0)