mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-24 10:38:36 +08:00
Refactored redir middleware to return errors
This commit is contained in:
parent
a39e71ca26
commit
c657948824
|
@ -41,15 +41,15 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
|
|||
redirects = append(redirects, rule)
|
||||
}
|
||||
|
||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
||||
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 redirects {
|
||||
if r.URL.Path == rule.From {
|
||||
http.Redirect(w, r, rule.To, rule.Code)
|
||||
break
|
||||
}
|
||||
}
|
||||
next(w, r)
|
||||
return next(w, r)
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user