Пример #1
0
        public void HandleRequest(HttpRequest req)
        {
            try
            {
                if (req.Server != this)
                {
                    req.Server = this;
                }

                Log("HandleRequest", $"{req.RemoteAddress}->{req.Url.Path}");

                HttpRequest request = req;
                {
                    if (Routing.ExecuteConditionalPassthroughs(request))
                    {
                        return;
                    }

                    //On each request
                    if (OnRequest != null)
                    {
                        OnRequest(request);
                    }
                    if (request.IsClosed)
                    {
                        return;
                    }

                    if (OnRequestPost != null)
                    {
                        OnRequestPost(request);
                    }

                    if (request.IsClosed)
                    {
                        return;
                    }

                    //Routing
                    if (Routing.ExecuteConditional(request))
                    {
                        return;
                    }

                    if (Routing.ExecuteRouting(request))
                    {
                        return;
                    }

                    if (Routing.ExecuteController(request))
                    {
                        return;
                    }

                    if (Routing.ExecuteFile(request))
                    {
                        return;
                    }

                    //Default Callback
                    if (OnDefaultRequest != null && !request.IsClosed)
                    {
                        OnDefaultRequest(request);
                    }
                }
            }
            catch (Exception ex)
            {
                if (OnException != null)
                {
                    OnException("HandleRequest", ex);
                }
                if (OnLog != null)
                {
                    OnLog("HandleRequest", $"Exception when handling request: {ex.Message}");
                }
            }
            finally
            {
                if (!req.IsClosed && !req.DisableAutoHandling)
                {
                    try
                    {
                        req.Close();
                    }
                    catch { }
                }
            }
        }