diff --git a/CHANGELOG.md b/CHANGELOG.md index dc6076524c0..ccf8f84d35b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ 1. [16733](https://github.com/influxdata/influxdb/pull/16733): Fix notification rule renaming panics from UI 1. [16769](https://github.com/influxdata/influxdb/pull/16769): Fix the tooltip for stacked line graphs +1. [16822](https://github.com/influxdata/influxdb/pull/16822): Fix issue with pkger/http stack crashing on dupe content type ## v2.0.0-beta.2 [2020-01-24] diff --git a/http/errors.go b/http/errors.go index 7c6b6d541d0..e6a399614ed 100644 --- a/http/errors.go +++ b/http/errors.go @@ -58,6 +58,13 @@ func CheckError(resp *http.Response) (err error) { } } + if resp.StatusCode == http.StatusUnsupportedMediaType { + return &platform.Error{ + Code: platform.EInvalid, + Msg: fmt.Sprintf("invalid media type: %q", resp.Header.Get("Content-Type")), + } + } + contentType := resp.Header.Get("Content-Type") if contentType == "" { // Assume JSON if there is no content-type. @@ -76,11 +83,9 @@ func CheckError(resp *http.Response) (err error) { switch mediatype { case "application/json": pe := new(platform.Error) - - parseErr := json.Unmarshal(buf.Bytes(), pe) - if parseErr != nil { + if err := json.Unmarshal(buf.Bytes(), pe); err != nil { line, _ := buf.ReadString('\n') - return errors.Wrap(stderrors.New(strings.TrimSuffix(line, "\n")), parseErr.Error()) + return errors.Wrap(stderrors.New(strings.TrimSuffix(line, "\n")), err.Error()) } return pe default: diff --git a/pkg/httpc/client.go b/pkg/httpc/client.go index 91e502e153c..c7863279466 100644 --- a/pkg/httpc/client.go +++ b/pkg/httpc/client.go @@ -152,7 +152,7 @@ func (c *Client) Req(method string, bFn BodyFn, urlPath string, rest ...string) } } if header != "" { - headers.Add(header, headerVal) + headers.Set(header, headerVal) } // w.Close here is necessary since we have to close any gzip writer // or other writer that requires closing.