diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs
index aa0a1234..68ef1788 100644
--- a/websocket-sharp/Server/HttpServer.cs
+++ b/websocket-sharp/Server/HttpServer.cs
@@ -112,6 +112,59 @@ namespace WebSocketSharp.Server
{
}
+ ///
+ /// Initializes a new instance of the class with
+ /// the specified HTTP URL.
+ ///
+ ///
+ ///
+ /// An instance initialized by this constructor listens for the incoming requests on
+ /// the host name and port in .
+ ///
+ ///
+ /// If doesn't include a port, either port 80 or 443 is used on
+ /// which to listen. It's determined by the scheme (http or https) in .
+ /// (Port 80 if the scheme is http.)
+ ///
+ ///
+ ///
+ /// A that represents the HTTP URL of the server.
+ ///
+ ///
+ /// is .
+ ///
+ ///
+ ///
+ /// is empty.
+ ///
+ ///
+ /// -or-
+ ///
+ ///
+ /// is invalid.
+ ///
+ ///
+ public HttpServer (string url)
+ {
+ if (url == null)
+ throw new ArgumentNullException ("url");
+
+ if (url.Length == 0)
+ throw new ArgumentException ("An empty string.", "url");
+
+ Uri uri;
+ string msg;
+ if (!tryCreateUri (url, out uri, out msg))
+ throw new ArgumentException (msg, "url");
+
+ var host = uri.DnsSafeHost;
+ var addr = host.ToIPAddress ();
+ if (!addr.IsLocal ())
+ throw new ArgumentException ("The host part isn't a local host name: " + url, "url");
+
+ init (host, addr, uri.Port, uri.Scheme == "https");
+ }
+
///
/// Initializes a new instance of the class with
/// the specified and .
@@ -683,6 +736,43 @@ namespace WebSocketSharp.Server
_receiveThread.Join (millisecondsTimeout);
}
+ private static bool tryCreateUri (string uriString, out Uri result, out string message)
+ {
+ result = null;
+
+ var uri = uriString.ToUri ();
+ if (uri == null || !uri.IsAbsoluteUri) {
+ message = "Not an absolute URI: " + uriString;
+ return false;
+ }
+
+ var schm = uri.Scheme;
+ if (!(schm == "http" || schm == "https")) {
+ message = "The scheme part isn't 'http' or 'https': " + uriString;
+ return false;
+ }
+
+ if (uri.PathAndQuery != "/") {
+ message = "Includes the path or query component: " + uriString;
+ return false;
+ }
+
+ if (uri.Fragment.Length > 0) {
+ message = "Includes the fragment component: " + uriString;
+ return false;
+ }
+
+ if (uri.Port < 1) {
+ message = "The port part is less than 1: " + uriString;
+ return false;
+ }
+
+ result = uri;
+ message = String.Empty;
+
+ return true;
+ }
+
#endregion
#region Public Methods