Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
Fix error handling and matching catch-all routes
Matthew Holt committed
May 23, 2019 at 14:42 UTC
5a4a1421de9cc3a9d5aba9e48c195030cc24f576
2 files changed
+9
-8
modules/caddyhttp/routes.go
+2
-1
@@ -31,7 +31,8 @@ func (sr ServerRoute) anyMatcherSetMatches(r *http.Request) bool {
31
return true
32
}
33
}
34
- return false
34
+ // if no matchers, always match
35
+ return len(sr.matcherSets) == 0
36
}
37
38
// MatcherSet is a set of matchers which
modules/caddyhttp/server.go
+7
-7
@@ -65,19 +65,19 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
65
repl.Set("http.error.id", handlerErr.ID)
66
}
67
68
- if len(s.Errors.Routes) == 0 {
69
- // TODO: polish the default error handling
70
- log.Printf("[ERROR] Handler: %s", err)
71
- if handlerErr, ok := err.(HandlerError); ok {
72
- w.WriteHeader(handlerErr.StatusCode)
73
- }
74
- } else {
68
+ if s.Errors != nil && len(s.Errors.Routes) > 0 {
69
errStack, w := s.Errors.Routes.BuildCompositeRoute(w, r)
70
err := s.executeCompositeRoute(w, r, errStack)
71
if err != nil {
72
// TODO: what should we do if the error handler has an error?
73
log.Printf("[ERROR] handling error: %v", err)
74
}
75
+ } else {
76
+ // TODO: polish the default error handling
77
+ log.Printf("[ERROR] Handler: %s", err)
78
+ if handlerErr, ok := err.(HandlerError); ok {
79
+ w.WriteHeader(handlerErr.StatusCode)
80
+ }
81
}
82
}
83
}