private RouteBuilder Register(string method, AppFunc handler) { if (handler == null) { throw new ArgumentNullException("handler"); } App.Use(async(ctx, next) => { if (string.Equals(ctx.Request.Method, method, StringComparison.OrdinalIgnoreCase)) { var path = ctx.Request.Path.Value.Trim('/'); var data = RouteBuilderHelper.MatchData(_urlTemplateSegments, path); if (data != null) { ctx.Set(Keys.RouteData, data); await handler(ctx, next); } else { await next(); } } else { await next(); } }); return(this); }
internal HandlerFunc GetHandler(IOwinContext ctx) { foreach (var route in _routes) { if (!string.Equals(ctx.Request.Method, route.Method, StringComparison.OrdinalIgnoreCase)) { continue; } var path = ctx.Request.Path.Value.Trim('/'); var data = RouteBuilderHelper.MatchData(route.Segments, path); if (data == null) { continue; } ctx.Set(Keys.RouteData, data); return(route.Handler); } return(null); }