diff --git a/config/config.go b/config/config.go index 0b91f20d..fa37e2a5 100644 --- a/config/config.go +++ b/config/config.go @@ -59,14 +59,17 @@ func (h *Header) HTTPHeader() http.Header { header := make(http.Header) for name, values := range *h { - var s []string - if values != nil { - s = make([]string, 0, len(values)) - for _, value := range values { - s = append(s, string(value)) - } + // HTTP allows for empty headers. The best representation of a + // header with a nil or empty set of values is a single empty + // string. + if len(values) == 0 { + header.Set(name, "") + continue + } + + for _, value := range values { + header.Add(name, string(value)) } - header[name] = s } return header diff --git a/config/config_test.go b/config/config_test.go index 1e031f50..74221b79 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -70,10 +70,13 @@ func TestHeaderHTTPHeader(t *testing.T) { "nil": nil, }, expected: http.Header{ - "single": []string{"v1"}, - "multi": []string{"v1", "v2"}, - "empty": []string{}, - "nil": nil, + // note that the conversion from config.header + // to http.Header will use the canonical form + // of the header names. + "Single": []string{"v1"}, + "Multi": []string{"v1", "v2"}, + "Empty": []string{""}, + "Nil": []string{""}, }, }, "nil": {