diff --git a/pkg/rules/rules.go b/pkg/rules/rules.go index 469bcbe56..a6bfedb1b 100644 --- a/pkg/rules/rules.go +++ b/pkg/rules/rules.go @@ -59,7 +59,14 @@ func (r *Router) AddRoute(rule string, priority int, handler http.Handler) error } route := r.NewRoute().Handler(handler).Priority(priority) - return addRuleOnRoute(route, buildTree()) + + err = addRuleOnRoute(route, buildTree()) + if err != nil { + route.BuildOnly() + return err + } + + return nil } type tree struct { diff --git a/pkg/rules/rules_test.go b/pkg/rules/rules_test.go index a6a79eace..ca38ef28f 100644 --- a/pkg/rules/rules_test.go +++ b/pkg/rules/rules_test.go @@ -29,6 +29,16 @@ func Test_addRoute(t *testing.T) { rule: "rulewithnotmatcher", expectedError: true, }, + { + desc: "Host empty", + rule: "Host(``)", + expectedError: true, + }, + { + desc: "PathPrefix empty", + rule: "PathPrefix(``)", + expectedError: true, + }, { desc: "PathPrefix", rule: "PathPrefix(`/foo`)", diff --git a/pkg/server/router/router_test.go b/pkg/server/router/router_test.go index 703de3c37..19ed56252 100644 --- a/pkg/server/router/router_test.go +++ b/pkg/server/router/router_test.go @@ -62,6 +62,29 @@ func TestRouterManager_Get(t *testing.T) { entryPoints: []string{"web"}, expected: expectedResult{StatusCode: http.StatusOK}, }, + { + desc: "empty host", + routersConfig: map[string]*dynamic.Router{ + "foo": { + EntryPoints: []string{"web"}, + Service: "foo-service", + Rule: "Host(``)", + }, + }, + serviceConfig: map[string]*dynamic.Service{ + "foo-service": { + LoadBalancer: &dynamic.ServersLoadBalancer{ + Servers: []dynamic.Server{ + { + URL: server.URL, + }, + }, + }, + }, + }, + entryPoints: []string{"web"}, + expected: expectedResult{StatusCode: http.StatusNotFound}, + }, { desc: "no load balancer", routersConfig: map[string]*dynamic.Router{