summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-23 14:42:14 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-23 14:42:14 -0600
commit5a4a1421de9cc3a9d5aba9e48c195030cc24f576 (patch)
treec0d661f4ddf899af32765ac8ffaeebf97a0fd50c /modules
parent34a25dd5580948ff5b83843b81e72bda1b133189 (diff)
Fix error handling and matching catch-all routes
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/routes.go3
-rw-r--r--modules/caddyhttp/server.go14
2 files changed, 9 insertions, 8 deletions
diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go
index 59f287e..14c9f32 100644
--- a/modules/caddyhttp/routes.go
+++ b/modules/caddyhttp/routes.go
@@ -31,7 +31,8 @@ func (sr ServerRoute) anyMatcherSetMatches(r *http.Request) bool {
return true
}
}
- return false
+ // if no matchers, always match
+ return len(sr.matcherSets) == 0
}
// MatcherSet is a set of matchers which
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index 7b14ffa..4a1aafd 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -65,19 +65,19 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
repl.Set("http.error.id", handlerErr.ID)
}
- if len(s.Errors.Routes) == 0 {
- // TODO: polish the default error handling
- log.Printf("[ERROR] Handler: %s", err)
- if handlerErr, ok := err.(HandlerError); ok {
- w.WriteHeader(handlerErr.StatusCode)
- }
- } else {
+ if s.Errors != nil && len(s.Errors.Routes) > 0 {
errStack, w := s.Errors.Routes.BuildCompositeRoute(w, r)
err := s.executeCompositeRoute(w, r, errStack)
if err != nil {
// TODO: what should we do if the error handler has an error?
log.Printf("[ERROR] handling error: %v", err)
}
+ } else {
+ // TODO: polish the default error handling
+ log.Printf("[ERROR] Handler: %s", err)
+ if handlerErr, ok := err.(HandlerError); ok {
+ w.WriteHeader(handlerErr.StatusCode)
+ }
}
}
}