mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-24 08:49:01 +01:00
Refactored rewrite middleware to return errors
This commit is contained in:
parent
c657948824
commit
878ae7ea89
1 changed files with 4 additions and 3 deletions
|
@ -28,15 +28,16 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
|
||||||
rewrites = append(rewrites, rule)
|
rewrites = append(rewrites, rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
// TODO: Why can't we just return an http.Handler here instead?
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(next middleware.HandlerFunc) middleware.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
for _, rule := range rewrites {
|
for _, rule := range rewrites {
|
||||||
if r.URL.Path == rule.From {
|
if r.URL.Path == rule.From {
|
||||||
r.URL.Path = rule.To
|
r.URL.Path = rule.To
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next(w, r)
|
return next(w, r)
|
||||||
}
|
}
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue