FindHandler() private method

private FindHandler ( string prefix ) : IPrefixHandler
prefix string
return IPrefixHandler
Example #1
0
 private void SetupResponse()
 {
     State = HttpStates.WRITEBEGIN;
     try {
         var handler = owner.FindHandler(path);
         if (handler == null)
         {
             throw new Http404Exception();
         }
         response = handler.HandleRequest(this);
         if (response == null)
         {
             throw new ArgumentException("Handler did not return a response");
         }
     }
     catch (Http404Exception ex) {
         Info(String.Format("{0} - Got a 404: {1}", this, path), ex);
         response = Error404.HandleRequest(this);
     }
     catch (Exception ex) {
         Warn(String.Format("{0} - Failed to process response", this), ex);
         response = Error500.HandleRequest(this);
     }
     SendResponse();
 }
Example #2
0
        private void SetupResponse()
        {
            State = HttpStates.WriteBegin;
            try {
                if (!owner.AuthorizeClient(this))
                {
                    throw new HttpStatusException(HttpCode.Denied);
                }
                if (string.IsNullOrEmpty(Path))
                {
                    throw new HttpStatusException(HttpCode.NotFound);
                }
                var handler = owner.FindHandler(Path);
                if (handler == null)
                {
                    throw new HttpStatusException(HttpCode.NotFound);
                }
                response = handler.HandleRequest(this);
                if (response == null)
                {
                    throw new ArgumentException("Handler did not return a response");
                }
            }
            catch (HttpStatusException ex) {
#if DEBUG
                Warn(String.Format("{0} - Got a {2}: {1}", this, path, ex.Code), ex);
#else
                DebugFormat("{0} - Got a {2}: {1}", this, Path, ex.Code);
#endif
                switch (ex.Code)
                {
                case HttpCode.NotFound:
                    response = error404.HandleRequest(this);
                    break;

                case HttpCode.Denied:
                    response = error403.HandleRequest(this);
                    break;

                case HttpCode.InternalError:
                    response = error500.HandleRequest(this);
                    break;

                default:
                    response = new StaticHandler(new StringResponse(
                                                     ex.Code,
                                                     "text/plain",
                                                     ex.Message
                                                     )).HandleRequest(this);
                    break;
                }
            }
            catch (Exception ex) {
                Warn($"{this} - Failed to process response", ex);
                response = error500.HandleRequest(this);
            }
            SendResponse();
        }