using System; namespace ln.http.router { public class HttpRoutingContext { public HttpRequest HttpRequest { get; } public string Path { get; set; } public string RoutedPath { get; set; } public HttpRoutingContext(HttpRequest httpRequest) : this(httpRequest, httpRequest.URI.AbsolutePath) { } public HttpRoutingContext(HttpRequest httpRequest, string path) { HttpRequest = httpRequest; Path = path; RoutedPath = ""; } HttpRoutingContext(HttpRequest httpRequest,string path,string routedPath) { HttpRequest = httpRequest; Path = path; RoutedPath = routedPath; } public HttpRoutingContext Routed(string residual) { return new HttpRoutingContext(HttpRequest, residual, RoutedPath + Path.Substring(0,Path.Length - residual.Length)); } public bool PopNext(out string next, out HttpRoutingContext nextRoutingContext) { next = Path; if (String.Empty.Equals(next) || "/".Equals(next)) { nextRoutingContext = null; return false; } int indSlash = next.IndexOf('/',1); if (indSlash > 0) next = next.Substring(0, indSlash-1); nextRoutingContext = Routed(Path.Substring(next.Length)); if (next[0] == '/') next = next.Substring(1); return true; } } }