From b6e0a74f252229b57f7663f25f67ad6a13153735 Mon Sep 17 00:00:00 2001 From: sta Date: Mon, 25 Apr 2016 15:44:55 +0900 Subject: [PATCH] [Modify] Polish it It's same as the HttpListener class. --- websocket-sharp/Server/WebSocketServer.cs | 26 ++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 457df8c6..cb5c4c01 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -63,6 +63,7 @@ namespace WebSocketSharp.Server private System.Net.IPAddress _address; private AuthenticationSchemes _authSchemes; private Func _credFinder; + private static readonly string _defaultRealm; private bool _dnsStyle; private string _hostname; private TcpListener _listener; @@ -79,6 +80,15 @@ namespace WebSocketSharp.Server #endregion + #region Static Constructor + + static WebSocketServer () + { + _defaultRealm = "SECRET AREA"; + } + + #endregion + #region Public Constructors /// @@ -393,13 +403,17 @@ namespace WebSocketSharp.Server /// /// Gets or sets the name of the realm associated with the server. /// + /// + /// If this property is or empty, "SECRET AREA" will be used as + /// the name of the realm. + /// /// /// A that represents the name of the realm. The default value is - /// "SECRET AREA". + /// . /// public string Realm { get { - return _realm ?? (_realm = "SECRET AREA"); + return _realm; } set { @@ -592,6 +606,12 @@ namespace WebSocketSharp.Server : null; } + private string getRealm () + { + var realm = _realm; + return realm != null && realm.Length > 0 ? realm : _defaultRealm; + } + private void init (string hostname, System.Net.IPAddress address, int port, bool secure) { _hostname = hostname ?? address.ToString (); @@ -642,7 +662,7 @@ namespace WebSocketSharp.Server try { var ctx = cl.GetWebSocketContext (null, _secure, _sslConfig, _logger); if (_authSchemes != AuthenticationSchemes.Anonymous && - !authenticate (ctx, _authSchemes, Realm, UserCredentialsFinder)) + !authenticate (ctx, _authSchemes, getRealm (), UserCredentialsFinder)) return; processRequest (ctx);