Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamashou committed Oct 10, 2023
1 parent c63c334 commit ab3bb8c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions clientv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,7 @@ func (c *Client) Post(ctx context.Context, operationName, query string, respData

gqlInfo := NewGQLRequestInfo(r)
body := new(bytes.Buffer)

req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.BaseURL, body)
if err != nil {
return fmt.Errorf("create request struct failed: %w", err)
}

var multipartFilesGroupsContentType string
if len(multipartFilesGroups) > 0 {
contentType, err := prepareMultipartFormBody(
body,
Expand All @@ -177,7 +172,7 @@ func (c *Client) Post(ctx context.Context, operationName, query string, respData
return fmt.Errorf("failed to prepare form body: %w", err)
}

req.Header.Set("Content-Type", contentType)
multipartFilesGroupsContentType = contentType
} else {
requestBody, err := json.Marshal(r)
if err != nil {
Expand All @@ -187,8 +182,17 @@ func (c *Client) Post(ctx context.Context, operationName, query string, respData
body = bytes.NewBuffer(requestBody)
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.BaseURL, body)
if err != nil {
return fmt.Errorf("create request struct failed: %w", err)
}

if req.Header.Get("Content-Type") == "" {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
if multipartFilesGroupsContentType != "" {
req.Header.Set("Content-Type", multipartFilesGroupsContentType)
} else {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
}

if req.Header.Get("Accept") == "" {
Expand Down

0 comments on commit ab3bb8c

Please sign in to comment.