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()) }; }
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); }
public void AddRoutes(Route[] routes) { foreach (var route in routes) AddRoute(route); }
public void AddRoute(Route route) { UpdateAppRoutes(route); UpdateOptions(route); }
private void UpdateOptions(Route route) { if (_options.ContainsKey(route.Resource)) _options[route.Resource] += "," + route.Method; else _options.Add(route.Resource, route.Method); }
private void UpdateAppRoutes(Route route) { if (_appRoutes.ContainsKey(route.Get())) _appRoutes[route.Get()] = route; else _appRoutes.Add(route.Get(), route); }
private bool UnauthorizedRoute(IRequest request, Route route) { return route.HasCredentials() && !Authenticator.Verify(route.Credentials, GetRequestCredentials(request)); }
public void AddRoutes(Route[] routes) { AppRoutes.AddRoutes(routes); }
public void AddRoute(Route route) { AppRoutes.AddRoute(route); }