/** 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); }
/** 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); } }
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); }); }
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(); } }
public WebHost(IServer server, HttpRequestDelegate requestDelegate) { this.server = server; this.requestDelegate = requestDelegate; }
private static HttpRequestDelegate m2(HttpRequestDelegate next) => async context => { await context.Response.Body.WriteAsync(Encoding.UTF8.GetBytes("word")); await next(context); };
/// <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; }
public void RemoveDelegateFunc(HttpRequestDelegate callback) { OnHttpRequest -= callback; }