Example #1
0
        // --------------------------------------------------------------------------------------
        // Handlers: Routing

        public static PartialHttpHandler GET() =>
        PartialHttpHandler.FromFunc(async(next, ctx) =>
        {
            if (ctx.Request.Method == HttpMethods.Get)
            {
                return(await next.Invoke(ctx));
            }
            return(false);
        });
Example #2
0
 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;
     }));
 }
Example #3
0
        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;
            }));
        }
Example #4
0
 // overload operator +
 public static PartialHttpHandler operator +(PartialHttpHandler self, PartialHttpHandler nextPartial)
 {
     return(PartialHttpHandler.FromFunc((next, ctx) => self.Invoke(nextPartial.WithNext(next), ctx)));
 }