private async Task HandleContextAsync(HttpListenerContext context) { IHttpListenerContextHandler listenerContextHandler = GetHttpListenerContextHandler(context); if (listenerContextHandler == null) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; context.Response.Close(); return; } Exception exception = null; try { await listenerContextHandler.HandleAsync(context); } catch (Exception e) { exception = e; } if (exception != null) { await HandleUnhandledException(context, exception); } }
private IHttpListenerContextHandler GetHttpListenerContextHandler(HttpListenerContext context) { IHttpListenerContextHandler listenerContextHandler = _handlers .FirstOrDefault(h => h.CanHandlePath(context.Request.RawUrl)); return(listenerContextHandler); }