fix: allow explicit empty request bodies (#281)

This commit is contained in:
Daniel Moran 2021-09-24 11:35:29 -04:00 committed by GitHub
parent e609d4462d
commit f17f21410c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View File

@ -478,15 +478,14 @@ func setBody(body interface{}, contentType string) (io.ReadCloser, error) {
err = json.NewEncoder(bodyBuf).Encode(body)
} else if xmlCheck.MatchString(contentType) {
err = xml.NewEncoder(bodyBuf).Encode(body)
} else {
err = fmt.Errorf("invalid body type %s", contentType)
}
if err != nil {
return nil, err
}
if bodyBuf.Len() == 0 {
return nil, fmt.Errorf("invalid body type %s", contentType)
}
return io.NopCloser(bodyBuf), nil
}

View File

@ -468,15 +468,14 @@ func setBody(body interface{}, contentType string) (io.ReadCloser, error) {
err = json.NewEncoder(bodyBuf).Encode(body)
} else if xmlCheck.MatchString(contentType) {
err = xml.NewEncoder(bodyBuf).Encode(body)
} else {
err = fmt.Errorf("invalid body type %s", contentType)
}
if err != nil {
return nil, err
}
if bodyBuf.Len() == 0 {
return nil, fmt.Errorf("invalid body type %s", contentType)
}
return io.NopCloser(bodyBuf), nil
}