Пример #1
0
 /// <summary>
 /// This method adds a new request routing element to the
 /// collection, consisting of a request pattern and a request
 /// handler.
 /// 
 /// Preconditions
 ///     pattern != null
 ///     pattern.Length >= 3
 ///     handler != null
 /// </summary>
 /// <param name="pattern">Request pattern (method, path).</param>
 /// <param name="handler">Request handler.</param>
 public void Add(string pattern, RequestHandler handler)
 {
     Contract.Requires(pattern != null);
     Contract.Requires(pattern.Length >= 3);
     Contract.Requires(handler != null);
     var e = Parse(pattern, handler);
     Contract.Requires(e != null);
     if (first == null)
     {
         first = e;
     }
     else
     {
         Element h = first;
         while (h.next != null) { h = h.next; }
         h.next = e;
     }
 }
Пример #2
0
 void IEnumerator.Reset()
 {
     current = null;
 }
Пример #3
0
 internal Enumerator(Element first)
 {
     this.first = first;
 }
Пример #4
0
 bool IEnumerator.MoveNext()
 {
     if (current == null)
     {
         current = first;
     }
     else
     {
         current = current.next;
     }
     return (current != null);
 }
Пример #5
0
        internal bool RequestMatch(Element e)
        {
            Contract.Requires(e != null);
            Contract.Requires(e.Path != null);
            Contract.Requires(e.Path.Length > 0);
            Contract.Requires(e.Path[0] == '/');
            // Pattern = ( Method | '*') path [ '*' ]
            string uri = RequestUri;
            Contract.Requires(uri != null);
            int uriLength = uri.Length;
            Contract.Requires(uriLength >= 1);
            if (uri[0] != '/')      // some proxies return absolute URIs
            {
                return false;
            }
            string method = RequestMethod;
            Contract.Requires(method != null);
            int methodLength = method.Length;
            Contract.Requires(methodLength >= 3);
            if ((method != e.Method) && (e.Method != "*")) { return false; }

            var pos = 1;
            if (relayDomain != null)    // try to match relay domain
            {
                int relayPrefixLength = relayDomain.Length + 1;
                if (uriLength <= relayPrefixLength) { return false; }
                while (pos != relayPrefixLength)
                {
                    if (uri[pos] != relayDomain[pos - 1]) { return false; }
                    pos = pos + 1;
                }
                if (uri[pos] != '/') { return false; }
                pos = pos + 1;
            }
            // try to match request pattern
            int patternLength = e.Path.Length;
            if (uriLength < (pos - 1 + patternLength)) { return false; }
            var i = 1;
            while (i != patternLength)
            {
                if (uri[pos] != e.Path[i]) { return false; }
                pos = pos + 1;
                i = i + 1;
            }
            return ((pos == uriLength) || (e.Wildcard));
        }