Commit b5fff09b authored by Peter Hellberg's avatar Peter Hellberg

headers: Changed Rule.Url to Rule.Path

Updated ServeHTTP comment to indicate that it is 
setting headers and not adding them to existing values.
parent a96c4d70
...@@ -18,10 +18,10 @@ type Headers struct { ...@@ -18,10 +18,10 @@ type Headers struct {
} }
// ServeHTTP implements the middleware.Handler interface and serves requests, // ServeHTTP implements the middleware.Handler interface and serves requests,
// adding headers to the response according to the configured rules. // setting headers on the response according to the configured rules.
func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
for _, rule := range h.Rules { for _, rule := range h.Rules {
if middleware.Path(r.URL.Path).Matches(rule.Url) { if middleware.Path(r.URL.Path).Matches(rule.Path) {
for _, header := range rule.Headers { for _, header := range rule.Headers {
if strings.HasPrefix(header.Name, "-") { if strings.HasPrefix(header.Name, "-") {
w.Header().Del(strings.TrimLeft(header.Name, "-")) w.Header().Del(strings.TrimLeft(header.Name, "-"))
...@@ -38,7 +38,7 @@ type ( ...@@ -38,7 +38,7 @@ type (
// Rule groups a slice of HTTP headers by a URL pattern. // Rule groups a slice of HTTP headers by a URL pattern.
// TODO: use http.Header type instead? // TODO: use http.Header type instead?
Rule struct { Rule struct {
Url string Path string
Headers []Header Headers []Header
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment