func (s *BackendSuite) TestFrontendBadParams(c *C) { // Bad route _, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", "/home -- afawf \\~", HTTPFrontendSettings{}) c.Assert(err, NotNil) // Empty params _, err = NewHTTPFrontend(route.NewMux(), "", "", "", HTTPFrontendSettings{}) c.Assert(err, NotNil) }
// vulcan func startVulcan() { mux := vulcan.NewMux() expr := fmt.Sprintf(`Method("%s") && Path("%s")`, "GET", "/hello") mux.HandleFunc(expr, helloHandler) http.ListenAndServe(":"+strconv.Itoa(port), mux) }
func (s *BackendSuite) TestFrontendDefaults(c *C) { f, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", `Path("/home")`, HTTPFrontendSettings{}) c.Assert(err, IsNil) c.Assert(f.GetId(), Equals, "f1") c.Assert(f.String(), Not(Equals), "") c.Assert(f.Route, Equals, `Path("/home")`) }
func (s *BackendSuite) TestFrontendsFromJSON(c *C) { f, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", `Path("/path")`, HTTPFrontendSettings{}) c.Assert(err, IsNil) bytes, err := json.Marshal(f) fs := []Frontend{*f} bytes, err = json.Marshal(map[string]interface{}{"Frontends": fs}) r := plugin.NewRegistry() c.Assert(r.AddSpec(connlimit.GetSpec()), IsNil) out, err := FrontendsFromJSON(route.NewMux(), bytes) c.Assert(err, IsNil) c.Assert(out, NotNil) c.Assert(out, DeepEquals, fs) }
func loadVulcanSingle(method, path string, handler http.HandlerFunc) http.Handler { re := regexp.MustCompile(":([^/]*)") mux := vulcan.NewMux() path = re.ReplaceAllString(path, "<$1>") expr := fmt.Sprintf(`Method("%s") && Path("%s")`, method, path) if err := mux.HandleFunc(expr, httpHandlerFunc); err != nil { panic(err) } return mux }
func loadVulcan(routes []route) http.Handler { re := regexp.MustCompile(":([^/]*)") mux := vulcan.NewMux() for _, route := range routes { path := re.ReplaceAllString(route.path, "<$1>") expr := fmt.Sprintf(`Method("%s") && Path("%s")`, route.method, path) if err := mux.HandleFunc(expr, httpHandlerFunc); err != nil { panic(err) } } return mux }
func (s *BackendSuite) TestFrontendBadOptions(c *C) { settings := []HTTPFrontendSettings{ HTTPFrontendSettings{ FailoverPredicate: "bad predicate", }, } for _, s := range settings { f, err := NewHTTPFrontend(route.NewMux(), "f1", "b", `Path("/home")`, s) c.Assert(err, NotNil) c.Assert(f, IsNil) } }
func (s *BackendSuite) TestNewFrontendWithOptions(c *C) { settings := HTTPFrontendSettings{ Limits: HTTPFrontendLimits{ MaxMemBodyBytes: 12, MaxBodyBytes: 400, }, FailoverPredicate: "IsNetworkError() && Attempts() <= 1", Hostname: "host1", TrustForwardHeader: true, } f, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", `Path("/home")`, settings) c.Assert(err, IsNil) c.Assert(f.Id, Equals, "f1") o := f.HTTPSettings() c.Assert(o.Limits.MaxMemBodyBytes, Equals, int64(12)) c.Assert(o.Limits.MaxBodyBytes, Equals, int64(400)) c.Assert(o.FailoverPredicate, NotNil) c.Assert(o.TrustForwardHeader, Equals, true) c.Assert(o.Hostname, Equals, "host1") }