コード例 #1
0
ファイル: AppRoutes.cs プロジェクト: swalker-/HttpServer
        static AppRoutes()
        {
            var authRoute = new Route(Methods.Get, "/logs", new HttpLibrary.Directors.FileResponse())
            {
                Credentials = new Credentials("admin", "hunter2")
            };
            var redirectRoute = new Route(Methods.Get, "/redirect", new Directors.GetResponse())
            {
                Redirect = "/"
            };

            Routes = new []
            {
                authRoute,
                redirectRoute,
                new Route(Methods.Delete, "/form", new DeleteResponse()),
                new Route(Methods.Get, "/file1", new Directors.GetResponse()),
                new Route(Methods.Get, "/text-file.txt", new Directors.FileResponse()),
                new Route(Methods.Get, "/", new Directors.GetResponse()),
                new Route(Methods.Get, "/partial_content.txt", new Directors.FileResponse()),
                new Route(Methods.Get, "/patch-content.txt", new Directors.GetResponse()),
                new Route(Methods.Patch, "/patch-content.txt", new PatchResponse()),
                new Route(Methods.Get, "/form", new Directors.GetResponse()),
                new Route(Methods.Put, "/form", new PostResponse()),
                new Route(Methods.Post, "/form", new PostResponse()),
                new Route(Methods.Delete, "/form", new DeleteResponse()),
                new Route(Methods.Options, "/method_options", new OptionsResponse())
            };
        }
コード例 #2
0
ファイル: AppRoutesSpec.cs プロジェクト: swalker-/HttpServer
 public void ItCanReturnQuoteForm()
 {
     var mRequest = new MockRequest() {Method = "GET", Resource = "/", Route="GET /"};
     var route = new Route("GET", "/", new QuoteFormResponse());
     var routes = new Router();
     routes.AddRoute(route);
     var responseString = routes.GetResponse(mRequest).ToString();
     var expectedResponseString = (new QuoteFormResponse()).Construct(mRequest).ToString();
     responseString.ShouldEqual(expectedResponseString);
 }
コード例 #3
0
ファイル: Router.cs プロジェクト: swalker-/HttpServer
 public void AddRoutes(Route[] routes)
 {
     foreach (var route in routes)
         AddRoute(route);
 }
コード例 #4
0
ファイル: Router.cs プロジェクト: swalker-/HttpServer
 public void AddRoute(Route route)
 {
     UpdateAppRoutes(route);
     UpdateOptions(route);
 }
コード例 #5
0
ファイル: Router.cs プロジェクト: swalker-/HttpServer
 private void UpdateOptions(Route route)
 {
     if (_options.ContainsKey(route.Resource))
         _options[route.Resource] += "," + route.Method;
     else
         _options.Add(route.Resource, route.Method);
 }
コード例 #6
0
ファイル: Router.cs プロジェクト: swalker-/HttpServer
 private void UpdateAppRoutes(Route route)
 {
     if (_appRoutes.ContainsKey(route.Get()))
         _appRoutes[route.Get()] = route;
     else
         _appRoutes.Add(route.Get(), route);
 }
コード例 #7
0
ファイル: Router.cs プロジェクト: swalker-/HttpServer
 private bool UnauthorizedRoute(IRequest request, Route route)
 {
     return route.HasCredentials() && !Authenticator.Verify(route.Credentials, GetRequestCredentials(request));
 }
コード例 #8
0
ファイル: Server.cs プロジェクト: swalker-/HttpServer
 public void AddRoutes(Route[] routes)
 {
     AppRoutes.AddRoutes(routes);
 }
コード例 #9
0
ファイル: Server.cs プロジェクト: swalker-/HttpServer
 public void AddRoute(Route route)
 {
     AppRoutes.AddRoute(route);
 }