Created
December 29, 2015 08:59
-
-
Save hackintoshrao/cdd59383d86ed373ad50 to your computer and use it in GitHub Desktop.
header middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Path) { | |
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment