diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-05-22 13:13:39 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-05-22 13:13:39 -0600 |
commit | 284fb3a98cae2e6e6ca79327988230a3a916996a (patch) | |
tree | ee52b5d7f144cf6510d1689e1ce06887ec213685 /modules/caddyhttp/caddyhttp.go | |
parent | bc00d840e845d42145954839b88f1e836cd51bfd (diff) |
Allow multiple matcher sets in routes (OR'ed together)
Also export MatchRegexp in case other matcher modules find it useful.
Add comments to the exported matchers.
Diffstat (limited to 'modules/caddyhttp/caddyhttp.go')
-rw-r--r-- | modules/caddyhttp/caddyhttp.go | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/modules/caddyhttp/caddyhttp.go b/modules/caddyhttp/caddyhttp.go index 2b194cd..1ff2cbc 100644 --- a/modules/caddyhttp/caddyhttp.go +++ b/modules/caddyhttp/caddyhttp.go @@ -53,13 +53,17 @@ func (app *App) Provision(ctx caddy2.Context) error { for i := range srv.Listen { srv.Listen[i] = repl.ReplaceAll(srv.Listen[i], "") } - err := srv.Routes.Provision(ctx) - if err != nil { - return fmt.Errorf("setting up server routes: %v", err) + if srv.Routes != nil { + err := srv.Routes.Provision(ctx) + if err != nil { + return fmt.Errorf("setting up server routes: %v", err) + } } - err = srv.Errors.Routes.Provision(ctx) - if err != nil { - return fmt.Errorf("setting up server error handling routes: %v", err) + if srv.Errors != nil { + err := srv.Errors.Routes.Provision(ctx) + if err != nil { + return fmt.Errorf("setting up server error handling routes: %v", err) + } } } @@ -187,13 +191,15 @@ func (app *App) automaticHTTPS() error { // find all qualifying domain names, de-duplicated domainSet := make(map[string]struct{}) for _, route := range srv.Routes { - for _, m := range route.matchers { - if hm, ok := m.(*MatchHost); ok { - for _, d := range *hm { - if !certmagic.HostQualifies(d) { - continue + for _, matcherSet := range route.matcherSets { + for _, m := range matcherSet { + if hm, ok := m.(*MatchHost); ok { + for _, d := range *hm { + if !certmagic.HostQualifies(d) { + continue + } + domainSet[d] = struct{}{} } - domainSet[d] = struct{}{} } } } @@ -245,9 +251,11 @@ func (app *App) automaticHTTPS() error { redirTo += "{http.request.uri}" redirRoutes = append(redirRoutes, ServerRoute{ - matchers: []RequestMatcher{ - MatchProtocol("http"), - MatchHost(domains), + matcherSets: []MatcherSet{ + { + MatchProtocol("http"), + MatchHost(domains), + }, }, responder: Static{ StatusCode: http.StatusTemporaryRedirect, // TODO: use permanent redirect instead |