@@ -39,11 +39,6 @@ urlPrefix:https://tc39.es/ecma262/#;type:dfn;spec:ecma-262
39
39
url:sec-list-and-record-specification-type;text:Record
40
40
</pre>
41
41
42
- <pre class=link-defaults>
43
- spec:websockets; type:interface; text:WebSocket
44
- spec:websockets; type:attribute; text:bufferedAmount; for:WebSocket
45
- </pre>
46
-
47
42
<pre class=biblio>
48
43
{
49
44
"HTTP": {
@@ -67,9 +62,6 @@ spec:websockets; type:attribute; text:bufferedAmount; for:WebSocket
67
62
"HSTS": {
68
63
"aliasOf": "RFC6797"
69
64
},
70
- "WSP": {
71
- "aliasOf": "RFC6455"
72
- },
73
65
"HTTPVERBSEC1": {
74
66
"publisher": "US-CERT",
75
67
"href": "https://www.kb.cert.org/vuls/id/867593",
@@ -168,16 +160,18 @@ exposes most of the networking functionality at a fairly low level of abstractio
168
160
169
161
<p> This specification depends on the Infra Standard. [[!INFRA]]
170
162
171
- <p> This specification uses terminology from the ABNF, Encoding, HTML, HTTP, IDL, MIME Sniffing,
172
- Streams, and URL Standards.
163
+ <p> This specification uses terminology from <cite> ABNF</cite> , <cite> Encoding</cite> ,
164
+ <cite> HTML</cite> , <cite> HTTP</cite> , <cite> MIME Sniffing</cite> , <cite> Streams</cite> ,
165
+ <cite> URL</cite> , <cite> Web IDL</cite> , and <cite> WebSockets</cite> .
173
166
[[!ABNF]]
174
167
[[!ENCODING]]
175
168
[[!HTML]]
176
169
[[!HTTP]]
177
- [[!WEBIDL]]
178
170
[[!MIMESNIFF]]
179
171
[[!STREAMS]]
180
172
[[!URL]]
173
+ [[!WEBIDL]]
174
+ [[!WEBSOCKETS]]
181
175
182
176
<p> <dfn>ABNF</dfn> means ABNF as augmented by HTTP (in particular the addition of <code> #</code> )
183
177
and RFC 7405. [[!RFC7405]]
805
799
<li><p> Otherwise, <a for=list>append</a> (<var> name</var> , <var> value</var> ) to <var> list</var> .
806
800
</ol>
807
801
808
- <p class=" note no-backref" > <a for="header list">Combine</a> is used by {{XMLHttpRequest}} and the
809
- <a lt="establish a WebSocket connection">WebSocket protocol handshake</a> .
802
+ <p class=note> <a for="header list">Combine</a> is used by {{XMLHttpRequest}} and the
803
+ <a spec=websockets lt="establish a WebSocket connection">WebSocket protocol handshake</a> .
810
804
811
805
<p> To <dfn>convert header names to a sorted-lowercase set</dfn> , given a <a for=/>list</a> of
812
806
<a lt=name for=header>names</a> <var> headerNames</var> , run these steps:
@@ -1804,8 +1798,8 @@ to not have to set <a for=/>request</a>'s <a for=request>referrer</a>.
1804
1798
<dd> This is a special mode used only when <a>navigating</a> between documents.
1805
1799
1806
1800
<dt> "<code> websocket</code> "
1807
- <dd> This is a special mode used only when <a lt="establish a WebSocket connection">establishing
1808
- a WebSocket connection</a> .
1801
+ <dd> This is a special mode used only when
1802
+ <a spec=websockets lt="establish a WebSocket connection">establishing a WebSocket connection</a> .
1809
1803
</dl>
1810
1804
1811
1805
<p> Even though the default <a for=/>request</a> <a for=request>mode</a> is "<code> no-cors</code> ",
@@ -8017,150 +8011,6 @@ fetch("https://www.example.com/")
8017
8011
8018
8012
8019
8013
8020
- <h2 id=websocket-protocol>WebSocket protocol alterations</h2>
8021
-
8022
- <div class=note>
8023
- <p> This section replaces part of the WebSocket protocol opening handshake client requirement to
8024
- integrate it with algorithms defined in Fetch. This way CSP, cookies, HSTS, and other Fetch-related
8025
- protocols are handled in a single location. Ideally the RFC would be updated with this language,
8026
- but it is never that easy. The WebSocket API, defined in the HTML Standard, has been updated to use
8027
- this language. [[!WSP]] [[!HTML]]
8028
-
8029
- <p> The way this works is by replacing The WebSocket Protocol's "establish a WebSocket connection"
8030
- algorithm with a new one that integrates with Fetch. "Establish a WebSocket connection" consists of
8031
- three algorithms: setting up a connection, creating and transmiting a handshake request, and
8032
- validating the handshake response. That layering is different from Fetch, which first creates a
8033
- handshake, then sets up a connection and transmits the handshake, and finally validates the
8034
- response. Keep that in mind while reading these alterations.
8035
- </div>
8036
-
8037
-
8038
- <h3 id=websocket-connections>Connections</h3>
8039
-
8040
- <p> To <dfn id=concept-websocket-connection-obtain>obtain a WebSocket connection</dfn> , given a
8041
- <var> url</var> , run these steps:
8042
-
8043
- <ol>
8044
- <li><p> Let <var ignore> host</var> be <var> url</var> 's <a for=url>host</a> .
8045
-
8046
- <li><p> Let <var ignore> port</var> be <var> url</var> 's <a for=url>port</a> .
8047
-
8048
- <li><p> Let <var ignore> secure</var> be false, if <var> url</var> 's <a for=url>scheme</a> is
8049
- "<code> http</code> ", and true otherwise.
8050
-
8051
- <li><p> Follow the requirements stated in step 2 to 5, inclusive, of the first set of steps in
8052
- <a href=https://datatracker.ietf.org/doc/html/rfc6455#section-4.1>section 4.1</a> of The WebSocket
8053
- Protocol to establish a <a lt="obtain a WebSocket connection">WebSocket connection</a> . [[!WSP]]
8054
-
8055
- <li><p> If that established a connection, return it, and return failure otherwise.
8056
- </ol>
8057
-
8058
- <p class=note> Although structured a little differently, carrying different properties, and
8059
- therefore not shareable, a WebSocket connection is very close to identical to an "ordinary"
8060
- <a>connection</a> .
8061
-
8062
-
8063
- <h3 id=websocket-opening-handshake>Opening handshake</h3>
8064
-
8065
- <p> To <dfn id=concept-websocket-establish>establish a WebSocket connection</dfn> , given a
8066
- <var> url</var> , <var> protocols</var> , and <var> client</var> , run these steps:
8067
-
8068
- <ol>
8069
- <li>
8070
- <p> Let <var> requestURL</var> be a copy of <var> url</var> , with its
8071
- <a for=url>scheme</a> set to
8072
- "<code> http</code> ", if <var> url</var> 's
8073
- <a for=url>scheme</a> is "<code> ws</code> ", and
8074
- to "<code> https</code> " otherwise.
8075
-
8076
- <p class="note no-backref"> This change of scheme is essential to integrate well with
8077
- <a lt=fetch for=/>fetching</a> . E.g., HSTS would not work without it. There is no real
8078
- reason for WebSocket to have distinct schemes, it's a legacy artefact.
8079
- [[!HSTS]]
8080
-
8081
- <li><p> Let <var> request</var> be a new <a for=/>request</a> , whose
8082
- <a for=request>URL</a> is <var> requestURL</var> ,
8083
- <a for=request>client</a> is <var> client</var> ,
8084
- <a>service-workers mode</a> is "<code> none</code> ",
8085
- <a for=request>referrer</a> is "<code> no-referrer</code> ",
8086
- <a for=request>mode</a> is "<code> websocket</code> ",
8087
- <a for=request>credentials mode</a> is
8088
- "<code> include</code> ",
8089
- <a for=request>cache mode</a> is "<code> no-store</code> ", and
8090
- <a for=request>redirect mode</a> is "<code> error</code> ".
8091
-
8092
- <li><p> <a for="header list">Append</a> (`<code> Upgrade</code> `, `<code> websocket</code> `) to
8093
- <var> request</var> 's <a for=request>header list</a> .
8094
-
8095
- <li><p> <a for="header list">Append</a> (`<code> Connection</code> `, `<code> Upgrade</code> `) to
8096
- <var> request</var> 's <a for=request>header list</a> .
8097
-
8098
- <li>
8099
- <p> Let <var> keyValue</var> be a nonce consisting of a randomly selected 16-byte value that has
8100
- been <a lt="forgiving-base64 encode">forgiving-base64-encoded</a> and <a>isomorphic encoded</a> .
8101
-
8102
- <p id=example-random-value class=example> If the randomly selected value was the byte sequence 0x01 0x02 0x03 0x04 0x05
8103
- 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10, <var> keyValue</var> would be
8104
- forgiving-base64-encoded to "<code> AQIDBAUGBwgJCgsMDQ4PEC==</code> " and isomorphic encoded
8105
- to `<code> AQIDBAUGBwgJCgsMDQ4PEC==</code> `.
8106
-
8107
- <li><p> <a for="header list">Append</a> (`<code> Sec-WebSocket-Key</code> `, <var> keyValue</var> ) to
8108
- <var> request</var> 's <a for=request>header list</a> .
8109
-
8110
- <li><p> <a for="header list">Append</a> (`<code> Sec-WebSocket-Version</code> `, `<code> 13</code> `) to
8111
- <var> request</var> 's <a for=request>header list</a> .
8112
-
8113
- <li><p> For each <var> protocol</var> in <var> protocols</var> , <a for="header list">combine</a>
8114
- (`<code> Sec-WebSocket-Protocol</code> `, <var> protocol</var> ) in <var> request</var> 's
8115
- <a for=request>header list</a> .
8116
-
8117
- <li>
8118
- <p> Let <var> permessageDeflate</var> be a user-agent defined
8119
- "<code> permessage-deflate</code> " extension <a for=/>header value</a> . [[!WSP]]
8120
-
8121
- <p id=example-permessage-deflate class=example> `<code> permessage-deflate; client_max_window_bits</code> `
8122
-
8123
- <li><p> <a for="header list">Append</a> (`<code> Sec-WebSocket-Extensions</code> `,
8124
- <var> permessageDeflate</var> ) to <var> request</var> 's <a for=request>header list</a> .
8125
-
8126
- <li>
8127
- <p> <a lt=fetch for=/>Fetch</a> <var> request</var> with <a for=fetch><i>useParallelQueue</i></a>
8128
- set to true, and <a for=fetch><i>processResponse</i></a> given <var> response</var> being these
8129
- steps:
8130
-
8131
- <ol>
8132
- <li><p> If <var> response</var> is a <a>network error</a> or its <a for=response>status</a> is not
8133
- 101, <a>fail the WebSocket connection</a> .
8134
-
8135
- <li>
8136
- <p> If <var> protocols</var> is not the empty list and <a>extracting header list values</a> given
8137
- `<code> Sec-WebSocket-Protocol</code> ` and <var> response</var> 's <a for=request>header list</a>
8138
- results in null, failure, or the empty byte sequence, then <a>fail the WebSocket connection</a> .
8139
-
8140
- <p class=note> This is different from the check on this header defined by The WebSocket Protocol.
8141
- That only covers a subprotocol not requested by the client. This covers a subprotocol requested
8142
- by the client, but not acknowledged by the server.
8143
-
8144
- <li><p> Follow the requirements stated step 2 to step 6, inclusive, of the last set of steps in
8145
- <a href=https://datatracker.ietf.org/doc/html/rfc6455#section-4.1>section 4.1</a> of The
8146
- WebSocket Protocol to validate <var> response</var> . This either results in
8147
- <a>fail the WebSocket connection</a> or <a>the WebSocket connection is established</a> .
8148
- </ol>
8149
- </ol>
8150
-
8151
- <p> <dfn>Fail the WebSocket connection</dfn> and <dfn>the WebSocket connection is established</dfn>
8152
- are defined by The WebSocket Protocol. [[!WSP]]
8153
-
8154
- <p class=warning> The reason redirects are not followed and this handshake is generally restricted is
8155
- because it could introduce serious security problems in a web browser context. For example, consider
8156
- a host with a WebSocket server at one path and an open HTTP redirector at another. Suddenly, any
8157
- script that can be given a particular WebSocket URL can be tricked into communicating to (and
8158
- potentially sharing secrets with) any host on the internet, even if the script checks that the URL
8159
- has the right hostname.
8160
- <!-- https://www.ietf.org/mail-archive/web/hybi/current/msg06951.html -->
8161
-
8162
-
8163
-
8164
8014
<h2 id=data-urls><code>data:</code> URLs</h2>
8165
8015
8166
8016
<p> For an informative description of <code> data:</code> URLs, see RFC 2397. This section replaces
@@ -8328,6 +8178,21 @@ resource — for non-<a>CORS requests</a> as well as <a>CORS
8328
8178
requests</a> — and do not use `<code> Vary</code> `.
8329
8179
8330
8180
8181
+ <h3 class=no-num id=websocket-protocol oldids=websocket-connections,websocket-opening-handshake,fail-the-websocket-connection,the-websocket-connection-is-established>WebSockets</h2>
8182
+
8183
+ <p> As part of establishing a connection, the {{WebSocket}} object initiates a special kind of
8184
+ <a for=/>fetch</a> (using a <a for=/>request</a> whose <a for=request>mode</a> is
8185
+ "<code> websocket</code> ") which allows it to share in many fetch policy decisions, such
8186
+ <cite> HTTP Strict Transport Security (HSTS)</cite> . Ultimately this results in fetch calling into
8187
+ <cite> WebSockets</cite> to obtain a dedicated connection. [[WEBSOCKETS]]
8188
+ [[HSTS]]
8189
+
8190
+ <p class=note> Fetch used to define
8191
+ <a id=concept-websocket-connection-obtain>obtain a WebSocket connection</a> and
8192
+ <a spec=websockets id=concept-websocket-establish>establish a WebSocket connection</a> directly, but
8193
+ both are now defined in <cite> WebSockets</cite> . [[WEBSOCKETS]]
8194
+
8195
+
8331
8196
8332
8197
<h2 id=fetch-elsewhere class=no-num>Using fetch in other standards</h2>
8333
8198
0 commit comments