Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Created December 29, 2015 08:59
Show Gist options
  • Save hackintoshrao/cdd59383d86ed373ad50 to your computer and use it in GitHub Desktop.
Save hackintoshrao/cdd59383d86ed373ad50 to your computer and use it in GitHub Desktop.
header middleware
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