Example #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)
}
Example #2
0
func MakeFrontend(route string, backendId string) engine.Frontend {
	f, err := engine.NewHTTPFrontend(routelib.NewMux(), UID("frontend"), backendId, route, engine.HTTPFrontendSettings{})
	if err != nil {
		panic(err)
	}
	return *f
}
Example #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")`)
}
Example #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)
}
Example #5
0
func scopedHandler(scope string, proxy http.Handler) (http.Handler, error) {
	if scope == "" {
		return proxy, nil
	}
	mux := route.NewMux()
	mux.SetNotFound(&DefaultNotFound{})
	if err := mux.Handle(scope, proxy); err != nil {
		return nil, err
	}
	return mux, nil
}
Example #6
0
func setDefaults(o Options) Options {
	if o.MetricsClient == nil {
		o.MetricsClient = metrics.NewNop()
	}
	if o.TimeProvider == nil {
		o.TimeProvider = &timetools.RealTime{}
	}
	if o.Router == nil {
		o.Router = route.NewMux()
	}
	return o
}
Example #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)
	}
}
Example #8
0
func (cmd *Command) upsertFrontendAction(c *cli.Context) {
	settings, err := getFrontendSettings(c)
	if err != nil {
		cmd.printError(err)
		return
	}
	f, err := engine.NewHTTPFrontend(route.NewMux(), c.String("id"), c.String("b"), c.String("route"), settings)
	if err != nil {
		cmd.printError(err)
		return
	}
	if err := cmd.client.UpsertFrontend(*f, c.Duration("ttl")); err != nil {
		cmd.printError(err)
		return
	}
	cmd.printOk("frontend upserted")
}
Example #9
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")
}
Example #10
0
func NewRegistry() *Registry {
	return &Registry{
		specs:  []*MiddlewareSpec{},
		router: route.NewMux(),
	}
}