Skip to content

Commit

Permalink
fix: remove duplicate content types from httpc requests
Browse files Browse the repository at this point in the history
2 issues from investigating this error. First is the status check func
did not identify it was a media unsupported issue adn tries to unmarshal
the empty response body. The 2nd, was the double content type headers were
causing an error. Locally this error does not surface, cannot repoduce on
macos, but in cloud it is persistent.

closes: #16819
  • Loading branch information
jsteenb2 committed Feb 11, 2020
1 parent ebfa85c commit e650c94
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
13 changes: 9 additions & 4 deletions http/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/httpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e650c94

Please sign in to comment.