Refactored HttpListener.cs

This commit is contained in:
sta 2014-10-14 14:04:50 +09:00
parent f46953a5ad
commit 85dd00626b

View File

@ -140,18 +140,14 @@ namespace WebSocketSharp.Net
/// Gets or sets the delegate called to select the scheme used to authenticate the clients. /// Gets or sets the delegate called to select the scheme used to authenticate the clients.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para>
/// If you set this property, the listener uses the authentication scheme selected by /// If you set this property, the listener uses the authentication scheme selected by
/// the delegate for each request. /// the delegate for each request. Or if you don't set, the listener uses the value of
/// </para> /// the <see cref="HttpListener.AuthenticationSchemes"/> property as the authentication
/// <para> /// scheme for all requests.
/// If you don't set, the listener uses the value of the <c>AuthenticationSchemes</c>
/// property as the authentication scheme for all requests.
/// </para>
/// </remarks> /// </remarks>
/// <value> /// <value>
/// A <c>Func&lt;<see cref="HttpListenerRequest"/>, <see cref="AuthenticationSchemes"/>&gt;</c> /// A <c>Func&lt;<see cref="HttpListenerRequest"/>, <see cref="AuthenticationSchemes"/>&gt;</c>
/// delegate that invokes the method(s) used to select an authentication scheme. The default /// delegate that references the method used to select an authentication scheme. The default
/// value is <see langword="null"/>. /// value is <see langword="null"/>.
/// </value> /// </value>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
@ -234,8 +230,8 @@ namespace WebSocketSharp.Net
/// sending the response to the client. /// sending the response to the client.
/// </summary> /// </summary>
/// <value> /// <value>
/// <c>true</c> if the listener doesn't return exceptions that occur when sending the response /// <c>true</c> if the listener shouldn't return those exceptions; otherwise, <c>false</c>.
/// to the client; otherwise, <c>false</c>. The default value is <c>false</c>. /// The default value is <c>false</c>.
/// </value> /// </value>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// This listener has been closed. /// This listener has been closed.
@ -297,7 +293,7 @@ namespace WebSocketSharp.Net
/// </summary> /// </summary>
/// <value> /// <value>
/// A <see cref="string"/> that represents the name of the realm. The default value is /// A <see cref="string"/> that represents the name of the realm. The default value is
/// <c>SECRET AREA</c>. /// <c>"SECRET AREA"</c>.
/// </value> /// </value>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// This listener has been closed. /// This listener has been closed.
@ -305,9 +301,9 @@ namespace WebSocketSharp.Net
public string Realm { public string Realm {
get { get {
CheckDisposed (); CheckDisposed ();
return _realm == null || _realm.Length == 0 return _realm != null && _realm.Length > 0
? (_realm = "SECRET AREA") ? _realm
: _realm; : (_realm = "SECRET AREA");
} }
set { set {
@ -348,7 +344,7 @@ namespace WebSocketSharp.Net
/// </summary> /// </summary>
/// <value> /// <value>
/// A <c>Func&lt;<see cref="IIdentity"/>, <see cref="NetworkCredential"/>&gt;</c> delegate /// A <c>Func&lt;<see cref="IIdentity"/>, <see cref="NetworkCredential"/>&gt;</c> delegate
/// that invokes the method used to find the credentials. The default value is a function /// that references the method used to find the credentials. The default value is a function
/// that only returns <see langword="null"/>. /// that only returns <see langword="null"/>.
/// </value> /// </value>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
@ -476,10 +472,10 @@ namespace WebSocketSharp.Net
{ {
CheckDisposed (); CheckDisposed ();
if (_prefixes.Count == 0) if (_prefixes.Count == 0)
throw new InvalidOperationException ("AddPrefix must be called before using this method."); throw new InvalidOperationException ("The listener has no URI prefix on which listens.");
if (!_listening) if (!_listening)
throw new InvalidOperationException ("Start must be called before using this method."); throw new InvalidOperationException ("The listener hasn't been started.");
// Lock _waitQueue early to avoid race conditions. // Lock _waitQueue early to avoid race conditions.
lock (_waitQueueSync) { lock (_waitQueueSync) {
@ -585,7 +581,7 @@ namespace WebSocketSharp.Net
/// </param> /// </param>
/// <exception cref="InvalidOperationException"> /// <exception cref="InvalidOperationException">
/// <para> /// <para>
/// This listener doesn't have any URI prefixes to listen on. /// This listener has no URI prefix on which listens.
/// </para> /// </para>
/// <para> /// <para>
/// -or- /// -or-
@ -681,7 +677,7 @@ namespace WebSocketSharp.Net
/// </returns> /// </returns>
/// <exception cref="InvalidOperationException"> /// <exception cref="InvalidOperationException">
/// <para> /// <para>
/// This listener doesn't have any URI prefixes to listen on. /// This listener has no URI prefix on which listens.
/// </para> /// </para>
/// <para> /// <para>
/// -or- /// -or-