|
|
|
@ -52,7 +52,7 @@ namespace WebSocketSharp.Net
|
|
|
|
private HttpListener _listener;
|
|
|
|
private HttpListener _listener;
|
|
|
|
private string _original;
|
|
|
|
private string _original;
|
|
|
|
private string _path;
|
|
|
|
private string _path;
|
|
|
|
private ushort _port;
|
|
|
|
private string _port;
|
|
|
|
private bool _secure;
|
|
|
|
private bool _secure;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
@ -108,9 +108,9 @@ namespace WebSocketSharp.Net
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int Port {
|
|
|
|
public string Port {
|
|
|
|
get {
|
|
|
|
get {
|
|
|
|
return (int) _port;
|
|
|
|
return _port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -120,29 +120,26 @@ namespace WebSocketSharp.Net
|
|
|
|
|
|
|
|
|
|
|
|
private void parse (string uriPrefix)
|
|
|
|
private void parse (string uriPrefix)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var defaultPort = uriPrefix.StartsWith ("https://") ? 443 : 80;
|
|
|
|
if (uriPrefix.StartsWith ("https"))
|
|
|
|
if (defaultPort == 443)
|
|
|
|
|
|
|
|
_secure = true;
|
|
|
|
_secure = true;
|
|
|
|
|
|
|
|
|
|
|
|
var len = uriPrefix.Length;
|
|
|
|
var len = uriPrefix.Length;
|
|
|
|
var startHost = uriPrefix.IndexOf (':') + 3;
|
|
|
|
var startHost = uriPrefix.IndexOf (':') + 3;
|
|
|
|
var root = uriPrefix.IndexOf ('/', startHost, len - startHost);
|
|
|
|
var root = uriPrefix.IndexOf ('/', startHost + 1, len - startHost - 1);
|
|
|
|
|
|
|
|
|
|
|
|
var colon = uriPrefix.LastIndexOf (':', root - 1, root - startHost - 1);
|
|
|
|
var colon = uriPrefix.LastIndexOf (':', root - 1, root - startHost - 1);
|
|
|
|
if (uriPrefix[root - 1] != ']' && colon > startHost) {
|
|
|
|
if (uriPrefix[root - 1] != ']' && colon > startHost) {
|
|
|
|
_host = uriPrefix.Substring (startHost, colon - startHost);
|
|
|
|
_host = uriPrefix.Substring (startHost, colon - startHost);
|
|
|
|
_port = (ushort) Int32.Parse (uriPrefix.Substring (colon + 1, root - colon - 1));
|
|
|
|
_port = uriPrefix.Substring (colon + 1, root - colon - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
_host = uriPrefix.Substring (startHost, root - startHost);
|
|
|
|
_host = uriPrefix.Substring (startHost, root - startHost);
|
|
|
|
_port = (ushort) defaultPort;
|
|
|
|
_port = _secure ? "443" : "80";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_path = uriPrefix.Substring (root);
|
|
|
|
var path = uriPrefix.Substring (root);
|
|
|
|
|
|
|
|
var pathLen = path.Length;
|
|
|
|
var pathLen = _path.Length;
|
|
|
|
_path = pathLen > 1 ? path.Substring (0, pathLen - 1) : path;
|
|
|
|
if (pathLen > 1)
|
|
|
|
|
|
|
|
_path = _path.Substring (0, pathLen - 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
@ -172,18 +169,14 @@ namespace WebSocketSharp.Net
|
|
|
|
if (root == startHost)
|
|
|
|
if (root == startHost)
|
|
|
|
throw new ArgumentException ("No host is specified.", "uriPrefix");
|
|
|
|
throw new ArgumentException ("No host is specified.", "uriPrefix");
|
|
|
|
|
|
|
|
|
|
|
|
if (uriPrefix[len - 1] != '/')
|
|
|
|
if (root == -1 || uriPrefix[len - 1] != '/')
|
|
|
|
throw new ArgumentException ("Ends without '/'.", "uriPrefix");
|
|
|
|
throw new ArgumentException ("Ends without '/'.", "uriPrefix");
|
|
|
|
|
|
|
|
|
|
|
|
var colon = uriPrefix.LastIndexOf (':', root - 1, root - startHost - 1);
|
|
|
|
if (uriPrefix[root - 1] == ':')
|
|
|
|
if (uriPrefix[root - 1] != ']' && colon > startHost) {
|
|
|
|
throw new ArgumentException ("No port is specified.", "uriPrefix");
|
|
|
|
int port;
|
|
|
|
|
|
|
|
if (!Int32.TryParse (uriPrefix.Substring (colon + 1, root - colon - 1), out port)
|
|
|
|
if (root == len - 2)
|
|
|
|
|| !port.IsPortNumber ()
|
|
|
|
throw new ArgumentException ("No path is specified.", "uriPrefix");
|
|
|
|
) {
|
|
|
|
|
|
|
|
throw new ArgumentException ("An invalid port is specified.", "uriPrefix");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The Equals and GetHashCode methods are required to detect duplicates in any collection.
|
|
|
|
// The Equals and GetHashCode methods are required to detect duplicates in any collection.
|
|
|
|
|