Ejemplo n.º 1
0
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)
}
Ejemplo n.º 2
0
// 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)
}
Ejemplo n.º 3
0
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")`)
}
Ejemplo n.º 4
0
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)
}
Ejemplo n.º 5
0
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
}
Ejemplo n.º 6
0
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
}
Ejemplo n.º 7
0
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)
	}
}
Ejemplo n.º 8
0
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")
}