From ab3bb8c472db73112fa7a76e32ee976bd9e54d3f Mon Sep 17 00:00:00 2001 From: Yamashou <1230124fw@gmail.com> Date: Tue, 10 Oct 2023 11:37:57 +0900 Subject: [PATCH] fix --- clientv2/client.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/clientv2/client.go b/clientv2/client.go index 5c2025b..85488c5 100644 --- a/clientv2/client.go +++ b/clientv2/client.go @@ -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, @@ -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 { @@ -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") == "" {