// -------------------------------------------------------------------------------------- // Handlers: Routing public static PartialHttpHandler GET() => PartialHttpHandler.FromFunc(async(next, ctx) => { if (ctx.Request.Method == HttpMethods.Get) { return(await next.Invoke(ctx)); } return(false); });
public static PartialHttpHandler routeStartsWith(string path) { return(PartialHttpHandler.FromFunc(async(next, ctx) => { var currentPath = GetPath(ctx); if (currentPath.StartsWith(path)) { return await next.Invoke(ctx); } return false; })); }
private static PartialHttpHandler handlerWithRootedPath(string path) { return(PartialHttpHandler.FromFunc(async(next, ctx) => { var saved = GetSavedSubPath(ctx); ctx.Items[RouteKey] = saved.OrDefault("") + path; var result = await next.Invoke(ctx); if (!result) { saved.Match(s => ctx.Items[RouteKey] = s, () => ctx.Items.Remove(RouteKey)); } return result; })); }
// overload operator + public static PartialHttpHandler operator +(PartialHttpHandler self, PartialHttpHandler nextPartial) { return(PartialHttpHandler.FromFunc((next, ctx) => self.Invoke(nextPartial.WithNext(next), ctx))); }