mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-27 12:25:55 +03: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)
|
||||
}
|
||||
|
||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: Why can't we just return an http.Handler here instead?
|
||||
return func(next middleware.HandlerFunc) middleware.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
for _, rule := range rewrites {
|
||||
if r.URL.Path == rule.From {
|
||||
r.URL.Path = rule.To
|
||||
break
|
||||
}
|
||||
}
|
||||
next(w, r)
|
||||
return next(w, r)
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue