Content-type fix (#659)

* charset fixes

* make linter happy (#661)

---------

Co-authored-by: grulex <god@vk.com>
Co-authored-by: Alexander Baranov <677093+sashabaranov@users.noreply.github.com>
This commit is contained in:
grulex
2024-02-15 16:11:58 +00:00
committed by GitHub
parent 11ad4b69d0
commit 66bae3ee73
2 changed files with 3 additions and 3 deletions

View File

@@ -107,13 +107,13 @@ func (c *Client) newRequest(ctx context.Context, method, url string, setters ...
}
func (c *Client) sendRequest(req *http.Request, v Response) error {
req.Header.Set("Accept", "application/json; charset=utf-8")
req.Header.Set("Accept", "application/json")
// Check whether Content-Type is already set, Upload Files API requires
// Content-Type == multipart/form-data
contentType := req.Header.Get("Content-Type")
if contentType == "" {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
req.Header.Set("Content-Type", "application/json")
}
res, err := c.config.HTTPClient.Do(req)

View File

@@ -76,7 +76,7 @@ func (c *Client) CreateSpeech(ctx context.Context, request CreateSpeechRequest)
}
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/audio/speech", string(request.Model)),
withBody(request),
withContentType("application/json; charset=utf-8"),
withContentType("application/json"),
)
if err != nil {
return