public HttpListener()
 {
     this._authSchemes     = WebSocketSharp.Net.AuthenticationSchemes.Anonymous;
     this._connections     = new Dictionary <HttpConnection, HttpConnection>();
     this._connectionsSync = ((ICollection)this._connections).SyncRoot;
     this._ctxQueue        = new List <HttpListenerContext>();
     this._ctxQueueSync    = ((ICollection)this._ctxQueue).SyncRoot;
     this._ctxRegistry     = new Dictionary <HttpListenerContext, HttpListenerContext>();
     this._ctxRegistrySync = ((ICollection)this._ctxRegistry).SyncRoot;
     this._logger          = new Logger();
     this._prefixes        = new HttpListenerPrefixCollection(this);
     this._waitQueue       = new List <HttpListenerAsyncResult>();
     this._waitQueueSync   = ((ICollection)this._waitQueue).SyncRoot;
 }
        internal async Task SetUser(
            AuthenticationSchemes scheme,
            string realm,
            Func <IIdentity, NetworkCredential> credentialsFinder)
        {
            var req = await _request.ConfigureAwait(false);

            var authRes = req.AuthenticationResponse;

            var id = authRes?.ToIdentity();

            if (id == null)
            {
                return;
            }

            NetworkCredential cred = null;

            try
            {
                cred = credentialsFinder(id);
            }
            catch
            {
            }

            if (cred == null)
            {
                return;
            }

            var valid = scheme == AuthenticationSchemes.Basic
                            ? ((HttpBasicIdentity)id).Password == cred.Password
                            : scheme == AuthenticationSchemes.Digest && ((HttpDigestIdentity)id).IsValid(cred.Password, realm, req.HttpMethod, null);

            if (valid)
            {
                _user = new GenericPrincipal(id, cred.Roles);
            }
        }