summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/server.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-07-09 12:58:39 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-07-09 12:58:39 -0600
commit4a3a418156e25aae17659142a4bf9259d7702c44 (patch)
tree559461c6504b7c1be38e0ddfbf0793b473ef8d66 /modules/caddyhttp/server.go
parent6dfba5fda82e216cffb117a62fcefbe61cd25a34 (diff)
Flatten HTTP handler config (#2662)
Differentiating middleware and responders has one benefit, namely that it's clear which module provides the response, but even then it's not a great advantage. Linear handler config makes a little more sense, giving greater flexibility and simplifying the core a bit, even though it's slightly awkward that handlers which are responders may not use the 'next' handler that is passed in at all.
Diffstat (limited to 'modules/caddyhttp/server.go')
-rw-r--r--modules/caddyhttp/server.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index d40a01d..8bc3a5a 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -65,9 +65,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
addHTTPVarsToReplacer(repl, r, w)
// build and execute the main handler chain
- stack, wrappedWriter := s.Routes.BuildCompositeRoute(w, r)
+ stack := s.Routes.BuildCompositeRoute(w, r)
stack = s.wrapPrimaryRoute(stack)
- err := s.executeCompositeRoute(wrappedWriter, r, stack)
+ err := s.executeCompositeRoute(w, r, stack)
if err != nil {
// add the raw error value to the request context
// so it can be accessed by error handlers
@@ -85,8 +85,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if s.Errors != nil && len(s.Errors.Routes) > 0 {
- errStack, wrappedWriter := s.Errors.Routes.BuildCompositeRoute(w, r)
- err := s.executeCompositeRoute(wrappedWriter, r, errStack)
+ errStack := 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] [%s %s] handling error: %v", r.Method, r.RequestURI, err)
@@ -154,6 +154,8 @@ func (s *Server) enforcementHandler(w http.ResponseWriter, r *http.Request, next
return next.ServeHTTP(w, r)
}
+// listenersUseAnyPortOtherThan returns true if there are any
+// listeners in s that use a port which is not otherPort.
func (s *Server) listenersUseAnyPortOtherThan(otherPort int) bool {
for _, lnAddr := range s.Listen {
_, addrs, err := caddy.ParseListenAddr(lnAddr)