This commit is contained in:
stanislavromanov 2015-05-08 17:43:32 +02:00
parent b2ee6638e4
commit a5a90fe6fc

View file

@ -5,6 +5,7 @@ package headers
import (
"net/http"
"strings"
"github.com/mholt/caddy/middleware"
)
@ -22,10 +23,14 @@ func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
for _, rule := range h.Rules {
if middleware.Path(r.URL.Path).Matches(rule.Url) {
for _, header := range rule.Headers {
if strings.HasPrefix(header.Name, "-") {
w.Header().Del(strings.TrimLeft(header.Name, "-"))
} else {
w.Header().Set(header.Name, header.Value)
}
}
}
}
return h.Next.ServeHTTP(w, r)
}