diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 4d7d083f..88e30956 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -1084,43 +1084,96 @@ namespace WebSocketSharp.Server #region Public Methods /// - /// Adds the WebSocket service with the specified behavior, , - /// and . + /// Adds a WebSocket service with the specified behavior, + /// , and . /// /// - /// - /// This method converts to URL-decoded string, - /// and removes '/' from tail end of . - /// - /// - /// returns an initialized specified typed - /// instance. - /// + /// is converted to a URL-decoded string and + /// '/' is trimmed from the end of the converted string if any. /// /// - /// A that represents the absolute path to the service to add. + /// A that represents an absolute path to + /// the service to add. /// - /// - /// A Func<T> delegate that references the method used to initialize - /// a new specified typed instance (a new - /// instance). + /// + /// + /// A Func<TBehavior> delegate. + /// + /// + /// It invokes the method called for creating + /// a new session instance for the service. + /// + /// + /// The method must create a new instance of + /// the specified behavior class and return it. + /// /// /// - /// The type of the behavior of the service to add. The TBehavior must inherit - /// the class. + /// + /// The type of the behavior for the service. + /// + /// + /// It must inherit the class. + /// /// - public void AddWebSocketService (string path, Func initializer) + /// + /// + /// is . + /// + /// + /// -or- + /// + /// + /// is . + /// + /// + /// + /// + /// is an empty string. + /// + /// + /// -or- + /// + /// + /// is not an absolute path. + /// + /// + /// -or- + /// + /// + /// includes either or both + /// query and fragment components. + /// + /// + /// -or- + /// + /// + /// is already in use. + /// + /// + public void AddWebSocketService ( + string path, Func creator + ) where TBehavior : WebSocketBehavior { - var msg = path.CheckIfValidServicePath () ?? - (initializer == null ? "'initializer' is null." : null); + if (path == null) + throw new ArgumentNullException ("path"); - if (msg != null) { - _log.Error (msg); - return; + if (creator == null) + throw new ArgumentNullException ("creator"); + + if (path.Length == 0) + throw new ArgumentException ("An empty string.", "path"); + + if (path[0] != '/') + throw new ArgumentException ("Not an absolute path.", "path"); + + if (path.IndexOfAny (new[] { '?', '#' }) > -1) { + var msg = "It includes either or both query and fragment components."; + throw new ArgumentException (msg, "path"); } - _services.Add (path, initializer); + _services.Add (path, creator); } ///