0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

Refactored proxy middleware to return errors

This commit is contained in:
Matthew Holt 2015-03-28 16:56:56 -06:00
parent 076d4e0ec5
commit 6bf36d922c

View file

@ -24,8 +24,8 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
rules = append(rules, 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 rules {
if middleware.Path(r.URL.Path).Matches(rule.from) {
@ -45,11 +45,11 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
// TODO: Construct this before; not during every request, if possible
proxy := httputil.NewSingleHostReverseProxy(baseUrl)
proxy.ServeHTTP(w, r)
return 0, nil
}
}
} else {
next(w, r)
}
}
return next(w, r)
}
}, nil
}