Skip to content

Commit

Permalink
Add HTTPS Upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjoan91 authored and meacer committed Oct 24, 2023
1 parent aa6f53e commit 54a3d49
Showing 1 changed file with 125 additions and 3 deletions.
128 changes: 125 additions & 3 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,17 @@ Unless stated otherwise, it is false.

<p class=note>This flag is for exclusive use by HTML's render-blocking mechanism. [[!HTML]]

<p>A <a for=/>request</a> has an associated boolean <dfn export for=request>is HTTPS upgrade</dfn>.
Unless stated otherwise, it is false.

<p class=note>This is for exclusive use by HTTPS Upgrading algorithm.

<p>A <a for=/>request</a> has an associated
<dfn export for=request>HTTPS upgrade fallback URL</dfn>, which is null or a <a for=/>URL</a>.
Unless otherwise stated, it is null.

<p class=note>This is for exclusive use by HTTPS Upgrading algorithm.

<hr>

<p>A <a for=/>request</a> has an associated
Expand Down Expand Up @@ -3265,6 +3276,106 @@ through TLS using ALPN. The protocol cannot be spoofed through HTTP requests in
</div>


<h3 id=https-upgrades>HTTPS upgrading</h3>

<p>User agents may optionally upgrade requests with URLs that are not
<a>potentially trustworthy URLs</a> to attempt to fetch them over
<a>potentially trustworthy URLs</a>. If an upgraded request fails with a network error, it is
retried over the original URL.

<p>The HTTPS upgrading algorithm consists of <a>upgrade an HTTP request</a> and
<a>HTTPS upgrade fallback</a> algorithms.

<h4 id=https-upgrades-upgrade>HTTPS upgrade algorithm</h4>
<div algorithm>

<p>To <dfn>upgrade an HTTP request</dfn> given a <a for=/>request</a> <var>request</var>:

<ol>
<li>
<p>If one or more of the following conditions are met, return:
<ul>
<li><p><var>request</var>'s <a for="request">destination</a> is not "<code>document</code>"

<li><p><var>request</var>'s <a for="request">method</a> is not "<code>GET</code>"

<li><p><var>request</var>'s <a for="request">URL</a>'s <a for="url">scheme</a> is not
"<code>http</code>"

<li><p><var>request</var>'s <a for="request">URL</a>'s <a for="url">host</a> is exempted from
upgrades in an <a>implementation-defined</a> way.
</ul>
</li>

<li>
<p>If <var>request</var>'s <a for=request>HTTPS upgrade fallback URL</a> is non-null, clear
<a for=request>is HTTPS upgrade</a> and <a for=request>HTTPS upgrade fallback URL</a> and return.

<p class=note>This is a fallback request that shouldn't be upgraded again.

<li>
<p>Otherwise, set the following fields:
<ul>
<li><p>Set <a for=request>HTTPS upgrade fallback URL</a> to <var>request</var>'s
<a for="request">URL</a>.

<li><p>Set <var>request</var>'s <a for="request">URL</a>'s <a for="url">scheme</a> to
"<code>https</code>".

<li><p>Set <a for=request>is HTTPS upgrade</a> to true.
</ul>
</li>
</ol>
</div>

<h4 id=https-upgrades-fallback>Fallback algorithm</h4>
<div algorithm>

<p>To run <dfn>HTTPS upgrade fallback</dfn> given a <a for=/>request</a> <var>request</var> and
<a for=/>response</a> <var>response</var>:

<ol>
<li><p>If <var>request</var>'s <a for=request>is HTTPS upgrade</a> is not set, then return
<var>response</var>.

<li>
<p>If <var>response</var> is a <a>network error</a>:

<p class=note>This means that the upgrade failed and initiates a fallback load.

<ol>
<li><p>Let <var>fallbackResponse</var> be a new <a for=/>response</a> whose
<a for=response>header list</a> is « », and its <code>Location</code> header is set to
<var>request</var>'s <a for=request>HTTPS upgrade fallback URL</a>, and its
<a for="response">status</a> set to 307.

<li><p>Return <var>fallbackResponse</var>.
</ol>

<li>
<p>Return <var>response</var>.

<p class=note>This means the upgrade was successful.

</ol>

<p class=note>User agents can implement a fast-fallback path by canceling slow fetches on upgraded
requests, in order to quickly initiate a fallback http load.

</div>

<h4 id=http-upgrades-examples>Examples</h4>

<p id=example-https-upgrade-good-https class=example><code>a.com</code> serves both
<code>http://a.com</code> and <code>https://a.com</code>. An eligible request to
<code>http://a.com</code> will be upgraded to <code>https://a.com</code>.

<p id=example-https-upgrade-bad-https class=example><code>a.com</code> serves
<code>http://a.com</code> but refuses connections on <code>https://a.com</code>. An eligible
request to <code>http://a.com</code> will be upgraded to <code>https://a.com</code>, but the fetch
will fail. A fallback request will be initiated to <code>http://a.com</code>.



<h2 id=http-extensions>HTTP extensions</h2>

Expand Down Expand Up @@ -4445,6 +4556,14 @@ steps:

<li><p><a>Upgrade <var>request</var> to a potentially trustworthy URL, if appropriate</a>.

<li>
<p>Optionally, run <a>upgrade an HTTP request</a> algorithm on <var>request</var>.

<p class=note>HTTPS upgrading only applies to requests with <a>HTTP(S) scheme</a>s, but it's done
in <a>main fetch</a> instead of <a>HTTP fetch</a> to ensure that
<a>upgrade a mixed content <var>request</var> to a potentially trustworthy URL, if appropriate</a>
step runs next and applies to the upgraded request.

<li><p><a>Upgrade a mixed content <var>request</var> to a potentially trustworthy URL, if appropriate</a>.

<li><p>If <a lt="block bad port">should <var>request</var> be blocked due to a bad port</a>,
Expand Down Expand Up @@ -5157,8 +5276,6 @@ these steps:
<p>If one of the following is true

<ul class=brief>
<li><p><var>response</var>'s <a for=response>type</a> is "<code>error</code>"

<li><p><var>request</var>'s <a for=request>mode</a> is "<code>same-origin</code>" and
<var>response</var>'s <a for=response>type</a> is "<code>cors</code>"

Expand Down Expand Up @@ -5246,6 +5363,10 @@ these steps:
<a>CORS check</a>, as <var>request</var>'s <a for=request>client</a> and the service worker can
have different embedder policies.

<li><p>If <var>request</var>'s <a for=request>is HTTPS upgrade</a> is set, set <var>response</var>
and <var>internalResponse</var> to the result of running <a>HTTPS upgrade fallback</a> given
<var>request</var> and <var>response</var>.

<li>
<p>If <var>internalResponse</var>'s <a for=response>status</a> is a <a>redirect status</a>:

Expand Down Expand Up @@ -8716,7 +8837,7 @@ resource — for non-<a>CORS requests</a> as well as <a>CORS
requests</a> — and do not use `<code>Vary</code>`.


<h3 class=no-num id=websocket-protocol oldids=websocket-connections,websocket-opening-handshake,fail-the-websocket-connection,the-websocket-connection-is-established>WebSockets</h2>
<h3 class=no-num id=websocket-protocol oldids=websocket-connections,websocket-opening-handshake,fail-the-websocket-connection,the-websocket-connection-is-established>WebSockets</h3>

<p>As part of establishing a connection, the {{WebSocket}} object initiates a special kind of
<a for=/>fetch</a> (using a <a for=/>request</a> whose <a for=request>mode</a> is
Expand Down Expand Up @@ -8980,6 +9101,7 @@ done only by navigations). The <a>fetch controller</a> is also used to
<a for=request>redirect mode</a> set to "<code>manual</code>".



<h2 id=acknowledgments class=no-num>Acknowledgments</h2>

<p>Thanks to
Expand Down

0 comments on commit 54a3d49

Please sign in to comment.