From 771cd4ffa1385c0b66ac17d0e82015f354359e36 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 12 May 2023 15:12:33 +0200 Subject: [PATCH] Allow HTTP(S) schemes in the WebSocket constructor And thereby relative URLs. They are instantly normalized to the ws: and wss: schemes. Tests: https://github.com/web-platform-tests/wpt/pull/39955 and https://github.com/web-platform-tests/wpt/pull/39978. Co-authored-by: Gus Caplan Co-authored-by: Adam Rice --- index.bs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index 2ecd377..9bc84e6 100644 --- a/index.bs +++ b/index.bs @@ -107,7 +107,7 @@ To obtain a WebSocket connect (including empty strings), if any, separated from each other by U+002F (/). 1. If |url|'s query is non-empty, append U+003F (?), followed by |url|'s query, to |resource name|. -1. Let |secure| be false, if |url|'s scheme is "`http`", and true otherwise. +1. Let |secure| be false, if |url|'s [=url/scheme=] is "`http`"; otherwise true. 1. Follow the requirements stated in step 2 to 5, inclusive, of the first set of steps in section 4.1 of The WebSocket Protocol to establish a WebSocket connection, passing @@ -128,8 +128,8 @@ therefore not shareable, a WebSocket connection is very close to identical to an To establish a WebSocket connection, given a |url|, |protocols|, and |client|, run these steps: -1. Let |requestURL| be a copy of |url|, with its scheme set to "`http`", if |url|'s - scheme is "`ws`", and to "`https`" otherwise. +1. Let |requestURL| be a copy of |url|, with its [=url/scheme=] set to "`http`", if |url|'s + [=url/scheme=] is "`ws`"; otherwise to "`https`".

This change of scheme is essential to integrate well with fetching. E.g., HSTS would not work without it. There is no real @@ -261,8 +261,8 @@ It can have the following values: connection. |url| is a string giving the URL over which the connection is established. - Only "`ws`" or "`wss`" schemes are allowed; others will cause a "{{SyntaxError}}" - {{DOMException}}. URLs with [=fragments=] will also cause such an exception. + Only "`ws`", "`wss`", "`http`", and "`https`" schemes are allowed; others will cause a + "{{SyntaxError}}" {{DOMException}}. URLs with [=fragments=] will always cause such an exception. |protocols| is either a string or an array of strings. If it is a string, it is equivalent to an array consisting of just that string; if it is omitted, it is equivalent to the empty array. @@ -320,8 +320,12 @@ It can have the following values: WebSocket(|url|, |protocols|) constructor steps are: - 1. Let |urlRecord| be the result of applying the [=URL parser=] to |url|. + 1. Let |baseURL| be [=this=]'s [=relevant settings object=]'s [=API base URL=]. + 1. Let |urlRecord| be the result of applying the [=URL parser=] to |url| with |baseURL|. 1. If |urlRecord| is failure, then throw a "{{SyntaxError}}" {{DOMException}}. + 1. If |urlRecord|'s [=url/scheme=] is "`http`", then set |urlRecord|'s [=url/scheme=] to "`ws`". + 1. Otherwise, if |urlRecord|'s [=url/scheme=] is "`https`", set |urlRecord|'s [=url/scheme=] to + "`wss`". 1. If |urlRecord|'s [=scheme=] is not "[=ws=]" or "[=wss=]", then throw a "{{SyntaxError}}" {{DOMException}}. 1. If |urlRecord|'s [=fragment=] is non-null, then throw a "{{SyntaxError}}" {{DOMException}}. @@ -800,6 +804,7 @@ repositories who helped develop the specification, especially Ian Hickson and An the respective original authors. Thanks to +devsnek and 平野裕 (Yutaka Hirano) for their contributions after the creation of the WebSockets Standard.