public async Task StartAsync(RequestDelegate handler) { try { Array.ForEach(_urls, url => _httpListener.Prefixes.Add(url)); _httpListener.Start(); while (true) { var listenerContext = await _httpListener.GetContextAsync(); var feature = new HttpListenerFeature(listenerContext); var features = new FeaturnCollection(); features.Set <IHttpRequestFerture>(feature); features.Set <IHttpResponseFerture>(feature); HttpContext context = new HttpContext(features); await handler(context); listenerContext.Response.Close(); } } catch (Exception ex) { throw; } }
public async Task StartAsync(RequestDelegate handler) { Array.ForEach(_urls, url => _httpListener.Prefixes.Add(url)); _httpListener.Start(); Console.WriteLine("Server started and is listening on: {0}", string.Join(';', _urls)); while (true) { var listenerContext = await _httpListener.GetContextAsync(); var feature = new HttpListenerFeature(listenerContext); var features = new FeatureCollection() .Set <IHttpRequestFeature>(feature) .Set <IHttpResponseFeature>(feature); var httpContext = new HttpContext(features); await handler(httpContext); listenerContext.Response.Close(); } }