NotFound() public static method

public static NotFound ( ) : HttpResponse
return SimpleHttpServer.Models.HttpResponse
示例#1
0
        protected virtual HttpResponse RouteRequest(Stream inputStream, Stream outputStream, HttpRequest request)
        {
            List <Route> routes = this.Routes.Where(x => Regex.Match(request.Url, x.UrlRegex).Success).ToList();

            if (!routes.Any())
            {
                return(HttpBuilder.NotFound());
            }

            Route route = routes.SingleOrDefault(x => x.Method == request.Method);

            if (route == null)
            {
                return(HttpBuilder.MethodNotAllowed());
            }

            request.Route = route;
            try
            {
                var result = route.Callable(request);

                if (result.IsValid())
                {
                    return(result);
                }

                return(HttpBuilder.InternalServerError(new Exception("Response is not valid")));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(HttpBuilder.InternalServerError(ex));
            }
        }
        protected virtual HttpResponse RouteRequest(TcpClient client, HttpRequest request)
        {
            if (!Routes.Any())
            {
                return(HttpBuilder.NotFound());
            }

            //Search Route
            var route = GetRoute(request);

            if (route == null)
            {
                return(HttpBuilder.NotFound());
            }

            // trigger the route handler...
            try
            {
                var discussion = new HttpDiscussion()
                {
                    Request = request, Response = null
                };

                route.Callable(discussion);

                return(discussion.Response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                return(HttpBuilder.InternalServerError());
            }
        }
示例#3
0
        protected virtual HttpResponse RouteRequest(Stream inputStream, Stream outputStream, HttpRequest request, IApp app)
        {
            string url = request.Url.Split('?')[0];

            List <Route> routes = this.Routes.Where(x =>
                                                    url.Equals(x.UrlRegex, StringComparison.OrdinalIgnoreCase) ||
                                                    Regex.Match(url, x.UrlRegex, RegexOptions.IgnoreCase).Success
                                                    ).ToList();

            if (!routes.Any())
            {
                return(HttpBuilder.NotFound(app));
            }

            Route route = routes.SingleOrDefault(x => x.Method == request.Method);

            if (route == null)
            {
                return new HttpResponse(app)
                       {
                           ReasonPhrase = "Method Not Allowed",
                           StatusCode   = "405",
                       }
            }
            ;

            // extract the path if there is one
            var match = Regex.Match(request.Url, route.UrlRegex);

            if (match.Groups.Count > 1)
            {
                request.Path = match.Groups[1].Value;
            }
            else
            {
                request.Path = request.Url;
            }

            // trigger the route handler...
            request.Route = route;
            try {
                return(route.Callable(request));
            } catch (Exception ex) {
                //log.Error(ex);
                return(HttpBuilder.InternalServerError(app));
            }
        }
示例#4
0
        protected virtual HttpResponse RouteRequest(Stream inputStream, Stream outputStream, HttpRequest request)
        {
            List <Route> routes = this.Routes.Where(x => Regex.Match(request.Url, x.UrlRegex).Success).ToList();

            if (!routes.Any())
            {
                return(HttpBuilder.NotFound());
            }

            Route route = routes.SingleOrDefault(x => x.Method == request.Method);

            if (route == null)
            {
                return new HttpResponse()
                       {
                           ReasonPhrase = "Method Not Allowed",
                           StatusCode   = "405",
                       }
            }
            ;

            // extract the path if there is one
            var match = Regex.Match(request.Url, route.UrlRegex);

            if (match.Groups.Count > 1)
            {
                request.Path = match.Groups[1].Value;
            }
            else
            {
                request.Path = request.Url;
            }

            // trigger the route handler...
            request.Route = route;
            try {
                return(route.Callable(request));
            } catch (Exception) {
                // log.Error(ex);
                // Console.WriteLine("here1");
                // Console.WriteLine(request);
                return(HttpBuilder.InternalServerError());
            }
        }
示例#5
0
        protected virtual HttpResponse RouteRequest(Stream inputStream, Stream outputStream, HttpRequest request)
        {
            List <Route> routes = this.Routes.Where(x => Regex.Match(request.Url, x.UrlRegex).Success).ToList();

            if (!routes.Any())
            {
                return(HttpBuilder.NotFound());
            }

            Route route = routes.SingleOrDefault(x => x.Method == request.Method);

            if (route == null)
            {
                return new HttpResponse()
                       {
                           ReasonPhrase = "Mетод не разрешен (Method Not Allowed)",
                           StatusCode   = "405",
                       }
            }
            ;

            // извлечь путь, если есть (extract the path if there is one)
            var match = Regex.Match(request.Url, route.UrlRegex);

            if (match.Groups.Count > 1)
            {
                request.Path = match.Groups[1].Value;
            }
            else
            {
                request.Path = request.Url;
            }

            // вызвать обработчик маршрута ... (trigger the route handler...)
            request.Route = route;
            try {
                return(route.Callable(request));
            } catch (Exception ex) {
                log.Error(ex);
                return(HttpBuilder.InternalServerError());
            }
        }
        protected virtual HttpResponse RouteRequest(Stream inputStream, Stream outputStream, HttpRequest request)
        {
            var routes = _routes.Where(x => Regex.Match(request.Url, x.UrlRegex, RegexOptions.IgnoreCase).Success).ToList();

            if (!routes.Any())
            {
                return(NotFoundOverrideCallable == null?HttpBuilder.NotFound() : NotFoundOverrideCallable(request));
            }
            var route = routes.SingleOrDefault(x => x.Method == request.Method);

            if (route == null)
            {
                return new HttpResponse()
                       {
                           ReasonPhrase = "Method Not Allowed",
                           StatusCode   = "405",
                       }
            }
            ;

            // extract the path if there is one
            var match = Regex.Match(request.Url, route.UrlRegex);

            request.Path = match.Groups.Count > 1 ? match.Groups[1].Value : request.Url;

            // trigger the route handler...
            request.Route = route;
            try
            {
                return(route.Callable(request));
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(HttpBuilder.InternalServerError());
            }
        }