private static bool removeSpecial(List <ListenerPrefix> prefixes, ListenerPrefix prefix)
        {
            if (prefixes == null)
            {
                return(false);
            }

            var count = prefixes.Count;

            for (int i = 0; i < count; i++)
            {
                if (prefixes [i].Path == prefix.Path)
                {
                    prefixes.RemoveAt(i);
                    return(true);
                }
            }

            return(false);
        }
        private HttpListener searchListener(Uri uri, out ListenerPrefix prefix)
        {
            prefix = null;
            if (uri == null)
            {
                return(null);
            }

            var          host        = uri.Host;
            var          port        = uri.Port;
            var          path        = HttpUtility.UrlDecode(uri.AbsolutePath);
            var          path_slash  = path [path.Length - 1] == '/' ? path : path + "/";
            HttpListener best_match  = null;
            var          best_length = -1;

            if (host != null && host.Length > 0)
            {
                foreach (var p in _prefixes.Keys)
                {
                    var ppath = p.Path;
                    if (ppath.Length < best_length)
                    {
                        continue;
                    }

                    if (p.Host != host || p.Port != port)
                    {
                        continue;
                    }

                    if (path.StartsWith(ppath) || path_slash.StartsWith(ppath))
                    {
                        best_length = ppath.Length;
                        best_match  = _prefixes [p];
                        prefix      = p;
                    }
                }

                if (best_length != -1)
                {
                    return(best_match);
                }
            }

            var list = _unhandled;

            best_match = matchFromList(host, path, list, out prefix);
            if (path != path_slash && best_match == null)
            {
                best_match = matchFromList(host, path_slash, list, out prefix);
            }

            if (best_match != null)
            {
                return(best_match);
            }

            list       = _all;
            best_match = matchFromList(host, path, list, out prefix);
            if (path != path_slash && best_match == null)
            {
                best_match = matchFromList(host, path_slash, list, out prefix);
            }

            if (best_match != null)
            {
                return(best_match);
            }

            return(null);
        }