From 4a3a418156e25aae17659142a4bf9259d7702c44 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 9 Jul 2019 12:58:39 -0600 Subject: 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. --- modules/caddyhttp/server.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'modules/caddyhttp/server.go') 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) -- cgit v1.2.3