summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/routes.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-01-12 13:39:32 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2020-01-12 13:39:32 -0700
commit64f0173948e9b87a8f898d451ef35daefedf2c50 (patch)
tree635019e8ff37ec2f87320b2795842ae5813e93eb /modules/caddyhttp/routes.go
parentfe5a531c58f9714bf379962c51d086a14661cfdb (diff)
http: Fix subroutes, ensure that next handlers can still be called
Diffstat (limited to 'modules/caddyhttp/routes.go')
-rw-r--r--modules/caddyhttp/routes.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go
index 4ae9bcd..431d1a5 100644
--- a/modules/caddyhttp/routes.go
+++ b/modules/caddyhttp/routes.go
@@ -147,12 +147,12 @@ func (routes RouteList) Provision(ctx caddy.Context) error {
// Compile prepares a middleware chain from the route list.
// This should only be done once: after all the routes have
// been provisioned, and before serving requests.
-func (routes RouteList) Compile() Handler {
+func (routes RouteList) Compile(next Handler) Handler {
var mid []Middleware
for _, route := range routes {
mid = append(mid, wrapRoute(route))
}
- stack := emptyHandler
+ stack := next
for i := len(mid) - 1; i >= 0; i-- {
stack = mid[i](stack)
}
@@ -167,6 +167,7 @@ func (routes RouteList) Compile() Handler {
func wrapRoute(route Route) Middleware {
return func(next Handler) Handler {
return HandlerFunc(func(rw http.ResponseWriter, req *http.Request) error {
+ // TODO: Update this comment, it seems we've moved the copy into the handler?
// copy the next handler (it's an interface, so it's just
// a very lightweight copy of a pointer); this is important
// because this is a closure to the func below, which