Allow setting multiple values for a request header

This commit is contained in:
Mislav Marohnić 2020-05-14 15:34:18 +02:00
parent 90fa193eaf
commit 7ffbde3e12

View file

@ -43,15 +43,15 @@ func httpRequest(client *http.Client, method string, p string, params interface{
return nil, err
}
if bodyIsJSON {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
for _, h := range headers {
idx := strings.IndexRune(h, ':')
if idx == -1 {
return nil, fmt.Errorf("header %q requires a value separated by ':'", h)
}
req.Header.Set(h[0:idx], strings.TrimSpace(h[idx+1:]))
req.Header.Add(h[0:idx], strings.TrimSpace(h[idx+1:]))
}
if bodyIsJSON && req.Header.Get("Content-Type") == "" {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
return client.Do(req)