public HttpServer2Route(string route, Http.Verb verb, Action <HttpServerRequestInfo> handler) { m_verb = verb; m_route = route; m_handler = handler; m_tokens = route.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); m_modes = new Mode[m_tokens.Length]; for (int i = 0; i < m_tokens.Length; i++) { var token = m_tokens[i]; var length = token.Length; if (token.Contains("[")) { if (token[0] == '[' && token[length - 1] == ']') { m_modes[i] = Mode.Variable; m_tokens[i] = token.Substring(1, length - 2); } else { m_modes[i] = Mode.Mixed; } } else { m_modes[i] = Mode.Literal; } } }
public HttpServer2Route Dispatch(string uri, Http.Verb verb, Dictionary <string, string> variables) { return(m_routes .Where(r => r.Verb == verb) .Where(r => r.Matches(uri, variables)) .FirstOrDefault()); }
public void Register(string prefix, Http.Verb verb, Func <HttpServerRequestInfo, bool> handler) { prefix = prefix ?? ""; prefix += "." + verb.ToString(); Register(prefix, handler); }
public void Register(Http.Verb verb, Func <HttpServerRequestInfo, bool> handler) { Register("", verb, handler); }