mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
adding in softer check for content type (#14097)
This commit is contained in:
@@ -109,7 +109,7 @@ func decodeResp(httpResp *http.Response, resp interface{}) error {
|
||||
return errors.Wrapf(err, "failed to read response body for %s", httpResp.Request.URL)
|
||||
}
|
||||
|
||||
if httpResp.Header.Get("Content-Type") != api.JsonMediaType {
|
||||
if !strings.Contains(httpResp.Header.Get("Content-Type"), api.JsonMediaType) {
|
||||
// 2XX codes are a success
|
||||
if strings.HasPrefix(httpResp.Status, "2") {
|
||||
return nil
|
||||
|
||||
@@ -99,7 +99,16 @@ func Test_decodeResp(t *testing.T) {
|
||||
type j struct {
|
||||
Foo string `json:"foo"`
|
||||
}
|
||||
|
||||
t.Run("200 JSON with charset", func(t *testing.T) {
|
||||
body := bytes.Buffer{}
|
||||
r := &http.Response{
|
||||
Status: "200",
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(&body),
|
||||
Header: map[string][]string{"Content-Type": {"application/json; charset=utf-8"}},
|
||||
}
|
||||
require.NoError(t, decodeResp(r, nil))
|
||||
})
|
||||
t.Run("200 non-JSON", func(t *testing.T) {
|
||||
body := bytes.Buffer{}
|
||||
r := &http.Response{
|
||||
|
||||
Reference in New Issue
Block a user