예제 #1
0
 /** get http */
 public void RequestGet(int id, string pageName, HttpRequestDelegate callback)
 {
     OnHttpRequest += callback;
     get(id, LiveDefines.DefaultURL + pageName);
     loading = Common.CreatePrefebToGameObject("Prefabs/UI/UILoading", loadingParent.transform);
     loading.transform.localPosition = new Vector3(0f, 0f, -5f);
 }
예제 #2
0
 /** post http */
 public void RequestPost(int id, string pageName, IDictionary <string, string> data, HttpRequestDelegate callback)
 {
     if (!bRequested)
     {
         bRequested     = true;
         OnHttpRequest += callback;
         post(id, LiveDefines.DefaultURL + pageName, data);
         loading = Common.CreatePrefebToGameObject("Prefabs/UI/UILoading", loadingParent.transform);
         loading.transform.localPosition = new Vector3(0f, 0f, -5f);
     }
 }
예제 #3
0
        public HttpRequestDelegate Build()
        {
            return(httpcontext => {
                HttpRequestDelegate next =
                    _ => { _.Response.StatusCode = 500; return Task.CompletedTask; };

                middlewares.Reverse();
                foreach (var middleware in middlewares)
                {
                    next = middleware(next);
                }
                return next(httpcontext);
            });
        }
예제 #4
0
        private static HttpRequestDelegate Auth(HttpRequestDelegate next) =>
        async context =>
        {
            var schemeProvider   = (IAuthenticationSchemeProvider)context.RequestServices.GetService(typeof(IAuthenticationSchemeProvider));
            var defaultAuthSchem = await schemeProvider.GetDefaultAuthenticateSchemeAsync();

            var authenticationServices = (IAuthenticationService)context.RequestServices.GetService(typeof(IAuthenticationService));
            var authResult             = await authenticationServices.AuthenicateAsync(context, defaultAuthSchem.Name);

            if (authResult.Succeeded)
            {
                context.User = authResult.Principal;
            }

            await next(context);
        };
        public async Task StartAsync(HttpRequestDelegate handler)
        {
            listener.Prefixes.Add(listenerUrl);
            listener.Start();
            while (true)
            {
                var listenerContext = await listener.GetContextAsync();

                var listerneFeature   = new HttpListenerFeature(listenerContext);
                var featureCollection = new FeatureCollection();
                featureCollection.SetService <IRequestFeature>(listerneFeature);
                featureCollection.SetService <IResponseFeature>(listerneFeature);
                var httpContext = new HttpContext(featureCollection);
                await handler(httpContext);

                listenerContext.Response.Close();
            }
        }
예제 #6
0
 public WebHost(IServer server, HttpRequestDelegate requestDelegate)
 {
     this.server          = server;
     this.requestDelegate = requestDelegate;
 }
예제 #7
0
 private static HttpRequestDelegate m2(HttpRequestDelegate next) =>
 async context =>
 {
     await context.Response.Body.WriteAsync(Encoding.UTF8.GetBytes("word"));
     await next(context);
 };
예제 #8
0
 /// <summary>
 /// Registers a URL handler.
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="handler">The handler.</param>
 protected void RegisterHandler(string url, HttpRequestDelegate handler)
 {
     _handlers[url] = handler;
 }
예제 #9
0
 public void RemoveDelegateFunc(HttpRequestDelegate callback)
 {
     OnHttpRequest -= callback;
 }