Skip to content

Commit

Permalink
[] (0) Factor out the definition of how to parse a Web Socket URL, so…
Browse files Browse the repository at this point in the history
… that there's no duplication. Clarify the definitions of ws: and wss:.

git-svn-id: http://svn.whatwg.org/webapps@3618 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Aug 14, 2009
1 parent 2021d26 commit 8114694
Showing 1 changed file with 141 additions and 117 deletions.
258 changes: 141 additions & 117 deletions source
Expand Up @@ -70388,64 +70388,27 @@ interface <dfn>WebSocket</dfn> {
<!-- beware, this is very similar to the steps for what happens
during a redirect, in the protocol section -->

<li><p><span title="parse a url">Parse</span> the <var
title="">url</var> argument.</p></li>

<li><p>If the previous step failed, or if <var title="">url</var>
does not have a <span title="url-scheme">&lt;scheme&gt;</span>
component whose value is either "<code title="">ws</code>" or
"<code title="">wss</code>", when compared in an <span>ASCII
case-insensitive</span> manner, then throw a
<code>SYNTAX_ERR</code> exception.</p></li>
<li><p><span>Parse a Web Socket URL's components</span> from the
<var title="">url</var> argument, to obtain <var
title="">host</var>, <var title="">port</var>, <var
title="">resource name</var>, and <var title="">secure</var>. If
this fails, throw a <code>SYNTAX_ERR</code> exception and abort
these steps.</p></li>

<li><p>If <var title="">protocol</var> is specified but is either
the empty string or contains characters that are not in the range
U+0021 .. U+007E, then throw a <code>SYNTAX_ERR</code>
exception.</p></li>
<li><p>If <var title="">port</var> is a port to which the user
agent is configured to block access, then throw a <span>security
exception</span>. (User agents typically block access to well-known
ports like SMTP.)</p></li>
<!--
e.g. http://www.mozilla.org/projects/netlib/PortBanning.html
-->

<li><p>Let <var title="">origin</var> be the <span title="ASCII
serialization of an origin">ASCII serialization</span> of the
<span>origin</span> of the script that invoked the <code
title="dom-WebSocket">WebSocket()</code> constructor,
<span>converted to ASCII lowercase</span>.</p></li>

<li><p>If the <span title="url-scheme">&lt;scheme&gt;</span>
component of <var title="">url</var> is "<code title="">ws</code>",
set <var title="">secure</var> to false; otherwise, the <span
title="url-scheme">&lt;scheme&gt;</span> component is "<code
title="">wss</code>", set <var title="">secure</var> to
true.</p></li>

<li><p>Let <var title="">host</var> be the value of the <span
title="url-host">&lt;host&gt;</span> component of <var
title="">url</var>, <span>converted to ASCII lowercase</span>.</p></li>

<li><p>If <var title="">url</var> has a <span
title="url-port">&lt;port&gt;</span> component, then let <var
title="">port</var> be that component's value; otherwise, there is
no explicit <var title="">port</var>.</p></li>

<li><p>If there is an explicit <var title="">port</var> and the
user agent is configured to block access to that port, then throw a
<span>security exception</span>. (User agents typically block
access to well-known ports like SMTP.)</p></li>
<!--
e.g. http://www.mozilla.org/projects/netlib/PortBanning.html
-->

<li><p>Let <var title="">resource name</var> be the value of the
<span title="url-path">&lt;path&gt;</span> component (which might
be empty) of <var title="">url</var>.</p></li>

<li><p>If <var title="">resource name</var> is the empty string,
set it to a single character U+002F SOLIDUS (/).</p></li>

<li><p>If <var title="">url</var> has a <span
title="url-query">&lt;query&gt;</span> component, then append a
single U+003F QUESTION MARK (?) character to <var title="">resource
name</var>, followed by the value of the <span
title="url-query">&lt;query&gt;</span> component.</p></li>

<li><p>Return a new <code>WebSocket</code> object, and continue
these steps in the background (without blocking scripts).</p></li>

Expand Down Expand Up @@ -70776,6 +70739,87 @@ WebSocket-Protocol: sample</pre>

<!--BOILERPLATE middle-ietf-conformance-->

<h6>Terminology</h6>

<p><dfn title="converted to ASCII lowercase">Converting a string to
ASCII lowercase</dfn> means replacing all characters in the range
U+0041 .. U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL
LETTER Z) with the corresponding characters in the range U+0061
.. U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z).</p>

<p>The term "URL" is used in this section in a manner consistent
with the terminology used in HTML, namely, to denote a string that
might or might not be a valid URI or IRI and to which certain error
handling behaviors will be applied when the string is parsed. <a
href="#refsHTML5">[HTML5]</a></p>



<h5>Parsing Web Socket URLs</h5>

<p>The steps to <dfn>parse a Web Socket URL's components</dfn> from
a string <var title="">url</var> are as follows. These steps return
either a <var title="">host</var>, a <var title="">port</var>, a
<var title="">resource name</var>, and a <var title="">secure</var>
flag, or they fail.</p>

<ol>

<li><p><span title="parse a url">Parse</span> the <var
title="">url</var> string using the <span>parse a Web
address</span> algorithm defined by the Web addresses
specification. <a href="#refsWEBADDRESSES">[WEBADDRESSES]</a></p>

<li><p>If the previous step failed, or if <var title="">url</var>
does not have a <span title="url-scheme">&lt;scheme&gt;</span>
component whose value is either "<code title="">ws</code>" or
"<code title="">wss</code>", when compared in an <span>ASCII
case-insensitive</span> manner, then fail this algorithm.</p></li>

<li><p>If <var title="">protocol</var> is specified but is either
the empty string or contains characters that are not in the range
U+0021 .. U+007E, then fail this algorithm.</p></li>

<li><p>If the <span title="url-scheme">&lt;scheme&gt;</span>
component of <var title="">url</var> is "<code title="">ws</code>",
set <var title="">secure</var> to false; otherwise, the <span
title="url-scheme">&lt;scheme&gt;</span> component is "<code
title="">wss</code>", set <var title="">secure</var> to
true.</p></li>

<li><p>Let <var title="">host</var> be the value of the <span
title="url-host">&lt;host&gt;</span> component of <var
title="">url</var>, <span>converted to ASCII
lowercase</span>.</p></li>

<li><p>If <var title="">url</var> has a <span
title="url-port">&lt;port&gt;</span> component, then let <var
title="">port</var> be that component's value; otherwise, there is
no explicit <var title="">port</var>.</p></li>

<li><p>If there is no explicit <var title="">port</var>, then: if
<var title="">secure</var> is false, let <var title="">port</var>
be 81, otherwise let <var title="">port</var> be 815.</p></li>

<li><p>Let <var title="">resource name</var> be the value of the
<span title="url-path">&lt;path&gt;</span> component (which might
be empty) of <var title="">url</var>.</p></li>

<li><p>If <var title="">resource name</var> is the empty string,
set it to a single character U+002F SOLIDUS (/).</p></li>

<li><p>If <var title="">url</var> has a <span
title="url-query">&lt;query&gt;</span> component, then append a
single U+003F QUESTION MARK (?) character to <var title="">resource
name</var>, followed by the value of the <span
title="url-query">&lt;query&gt;</span> component.</p></li>

<li><p>Return <var title="">host</var>, <var title="">port</var>,
<var title="">resource name</var>, and <var
title="">secure</var>.</p></li>

</ol>


<h5>Client-side requirements</h5>

Expand All @@ -70790,27 +70834,18 @@ WebSocket-Protocol: sample</pre>
<h6>Handshake</h6>

<p>When the user agent is to <dfn>establish a Web Socket
connection</dfn> to a host <var title="">host</var>, optionally on
port <var title="">port</var>, from an origin <var
title="">origin</var>, with a flag <var title="">secure</var>, with
a particular <var title="">resource name</var>, and optionally with
a particular <var title="">protocol</var>, it must run the following
steps.</p>
connection</dfn> to a host <var title="">host</var>, on a port <var
title="">port</var>, from an origin <var title="">origin</var>, with
a flag <var title="">secure</var>, with a particular <var
title="">resource name</var>, and optionally with a particular <var
title="">protocol</var>, it must run the following steps.</p>

<p class="note">The <var title="">host</var> and <var
title="">origin</var> strings will be all-lowercase when this
algorithm is invoked.</p>

<ol>

<li>

<p>If there is no explicit <var title="">port</var>, then: if <var
title="">secure</var> is false, let <var title="">port</var> be 81,
otherwise let <var title="">port</var> be 815.</p>

</li>

<li>

<p>If the user agent already has a Web Socket connection to the
Expand Down Expand Up @@ -71363,61 +71398,37 @@ Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=</pre>

<dd>

<!-- this is very similar to the constructor's steps -->

<p><span title="parse a url">Parse</span> the value of the
entry. If this fails, or if the parsed <span>URL</span> does not
have a <span title="url-scheme">&lt;scheme&gt;</span> component
whose value is either "<code title="">ws</code>" or "<code
title="">wss</code>", when compared in an <span>ASCII
case-insensitive</span> manner, then <span>fail the Web Socket
connection</span> and abort these steps.</p>

<p>If <var title="">secure</var> is true but the newly parsed
<span>URL</span>'s <span
title="url-scheme">&lt;scheme&gt;</span> component is an
<span>ASCII case-insensitive</span> match for "<code
title="">ws</code>", then <span>fail the Web Socket
connection</span> and abort these steps. Otherwise, if <var
title="">secure</var> is false but the newly parsed
<span>URL</span>'s <span
title="url-scheme">&lt;scheme&gt;</span> component is an
<span>ASCII case-insensitive</span> match for "<code
title="">wss</code>", then set <var title="">secure</var> to
true.</p>

<p>Let <var title="">host</var> be the value of the <span
title="url-host">&lt;host&gt;</span> component of <var
title="">url</var>, <span>converted to ASCII
lowercase</span>.</p>

<p>If <var title="">url</var> has a <span
title="url-port">&lt;port&gt;</span> component, then let <var
title="">port</var> be that component's value; otherwise, there
is no explicit <var title="">port</var>.</p>

<p>If there is an explicit <var title="">port</var> and the user
agent is configured to block access to that port, then
<span>fail the Web Socket connection</span> and abort these
steps.</p>

<p>Let <var title="">resource name</var> be the value of the
<span title="url-path">&lt;path&gt;</span> component (which
might be empty) of <var title="">url</var>.</p>
<ol>

<p>If <var title="">resource name</var> is the empty string, set
it to a single character U+002F SOLIDUS (/).</p>
<li><p>Let <var title="">was secure</var> have the value of
<var title="">secure</var>.</p></li>

<li><p><span>Parse a Web Socket URL's components</span> from
the <var title="">url</var> argument, to obtain new values for
<var title="">host</var>, <var title="">port</var>, <var
title="">resource name</var>, and <var
title="">secure</var>. If this fails, <span>fail the Web Socket
connection</span> and abort these steps.</p></li>

<li><p>If <var title="">was secure</var> is true but <var
title="">secure</var> is now false, <span>fail the Web Socket
connection</span> and abort these steps.</p></li>

<li><p>If <var title="">port</var> is a port to which the user
agent is configured to block access, then <span>fail the Web
Socket connection</span> and abort these steps. (User agents
typically block access to well-known ports like SMTP.)</p></li>
<!--
e.g. http://www.mozilla.org/projects/netlib/PortBanning.html
-->

<p>If <var title="">url</var> has a <span
title="url-query">&lt;query&gt;</span> component, then append a
single U+003F QUESTION MARK (?) character to <var
title="">resource name</var>, followed by the value of the <span
title="url-query">&lt;query&gt;</span> component.</p>
<li><p>Close the connection if the server has not already done
so.</p></li>

<p>Close the connection if the server has not already done
so.</p>
<li><p>Jump back to the first step of the overall algorithm
(the very top of the handshake).</p></li>

<p>Jump back to the first step of this algorithm.</p>
</ol>

</dd>

Expand Down Expand Up @@ -71873,6 +71884,9 @@ Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=</pre>

<h6>Registration of ws: scheme</h6>

<p>A <code title="">ws:</code> URL identifies a Web Socket server
and resource name.</p>

<dl>

<dt>URI scheme name.</dt>
Expand All @@ -71882,7 +71896,10 @@ Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=</pre>
<dd>Permanent.</dd>

<dt>URI scheme syntax.</dt>
<dd>"ws" ":" hier-part [ "?" query ]</dd>
<dd>
<p>In ABNF terms using the terminals from the IRI specifications: <a href="#refsRFC5238">[RFC5238]</a> <a href="#refsRFC3987">[RFC3987]</a></p>
<pre>"ws" ":" ihier-part [ "?" iquery ]</pre>
</dd>

<dt>URI scheme semantics.</dt>
<dd>The only operation for this scheme is to open a connection
Expand Down Expand Up @@ -71914,6 +71931,10 @@ Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=</pre>

<h6>Registration of wss: scheme</h6>

<p>A <code title="">wss:</code> URL identifies a Web Socket server
and resource name, and indicates that traffic over that connection
is to be encrypted.</p>

<dl>

<dt>URI scheme name.</dt>
Expand All @@ -71923,7 +71944,10 @@ Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=</pre>
<dd>Permanent.</dd>

<dt>URI scheme syntax.</dt>
<dd>"wss" ":" hier-part [ "?" query ]</dd>
<dd>
<p>In ABNF terms using the terminals from the IRI specifications: <a href="#refsRFC5238">[RFC5238]</a> <a href="#refsRFC3987">[RFC3987]</a></p>
<pre>"ws" ":" ihier-part [ "?" iquery ]</pre>
</dd>

<dt>URI scheme semantics.</dt>
<dd>The only operation for this scheme is to open a connection
Expand Down

0 comments on commit 8114694

Please sign in to comment.