Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow HTTP(S) schemes in the WebSocket constructor #45

Merged
merged 3 commits into from
May 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow HTTP(S) schemes in the WebSocket constructor
And thereby relative URLs. They are instantly normalized to the ws: and wss: schemes.

Tests: web-platform-tests/wpt#39955.

Closes #37.
  • Loading branch information
devsnek authored and annevk committed May 11, 2023
commit 6fb220bc849ee9299f9ff7dd52e9e764ea9e58aa
16 changes: 10 additions & 6 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ To <dfn export id=concept-websocket-connection-obtain>obtain a WebSocket connect
(including empty strings), if any, separated from each other by U+002F (/).
1. If |url|'s <a for=url>query</a> is non-empty, append U+003F (?), followed by |url|'s
<a for=url>query</a>, to |resource name|.
1. Let |secure| be false, if |url|'s <a for=url>scheme</a> 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 <a
href=https://datatracker.ietf.org/doc/html/rfc6455#section-4.1>section 4.1</a> of The WebSocket
Protocol to establish a <a lt="obtain a WebSocket connection">WebSocket connection</a>, passing
Expand All @@ -128,8 +128,8 @@ therefore not shareable, a WebSocket connection is very close to identical to an
To <dfn id=concept-websocket-establish>establish a WebSocket connection</dfn>, given a
|url|, |protocols|, and |client|, run these steps:

1. Let |requestURL| be a copy of |url|, with its <a for=url>scheme</a> set to "`http`", if |url|'s
<a for=url>scheme</a> 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`".

<p class="note no-backref">This change of scheme is essential to integrate well with
<a lt=fetch for=/>fetching</a>. E.g., HSTS would not work without it. There is no real
Expand Down Expand Up @@ -261,8 +261,8 @@ It can have the following values:
connection.

|url| is a string giving the <a for=/>URL</a> 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.
Expand Down Expand Up @@ -320,8 +320,12 @@ It can have the following values:
WebSocket(|url|, |protocols|)</code></dfn>
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
"`https`".
annevk marked this conversation as resolved.
Show resolved Hide resolved
1. If |urlRecord|'s [=scheme=] is not "<code>[=ws=]</code>" or "<code>[=wss=]</code>", then throw a
"{{SyntaxError}}" {{DOMException}}.
1. If |urlRecord|'s [=fragment=] is non-null, then throw a "{{SyntaxError}}" {{DOMException}}.
Expand Down