Allow multiple values for an HTTP header and

add a test to ensure this works.
This commit is contained in:
Garrett Squire
2016-07-20 14:23:55 -07:00
parent beae16f07c
commit e7c842215e
2 changed files with 36 additions and 0 deletions
+4
View File
@@ -24,8 +24,12 @@ func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
for _, rule := range h.Rules {
if httpserver.Path(r.URL.Path).Matches(rule.Path) {
for _, header := range rule.Headers {
// One can either delete a header, add multiple values to a header, or simply
// set a header.
if strings.HasPrefix(header.Name, "-") {
w.Header().Del(strings.TrimLeft(header.Name, "-"))
} else if strings.HasPrefix(header.Name, "+") {
w.Header().Add(strings.TrimLeft(header.Name, "+"), replacer.Replace(header.Value))
} else {
w.Header().Set(header.Name, replacer.Replace(header.Value))
}