Exemple #1
0
        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);
            }
        }
Exemple #2
0
        private IHttpListenerContextHandler GetHttpListenerContextHandler(HttpListenerContext context)
        {
            IHttpListenerContextHandler listenerContextHandler = _handlers
                                                                 .FirstOrDefault(h => h.CanHandlePath(context.Request.RawUrl));

            return(listenerContextHandler);
        }