Skip to content

Commit a937cd2

Browse files
committed
chore: Refactor multipart request handling and logging
1 parent c8dbe8b commit a937cd2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

httpclient/multipartrequest.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package httpclient
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/base64"
67
"fmt"
78
"io"
@@ -58,8 +59,12 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
5859
// Construct the full URL for the API endpoint.
5960
url := c.APIHandler.ConstructAPIResourceEndpoint(endpoint, log)
6061

61-
// Create the HTTP request
62-
req, err := http.NewRequest(method, url, body)
62+
// Create a context with timeout
63+
ctx, cancel := context.WithTimeout(context.Background(), c.clientConfig.ClientOptions.Timeout.CustomTimeout.Duration())
64+
defer cancel()
65+
66+
// Create the HTTP request with context
67+
req, err := http.NewRequestWithContext(ctx, method, url, body)
6368
if err != nil {
6469
log.Error("Failed to create HTTP request", zap.Error(err))
6570
return nil, err
@@ -286,8 +291,6 @@ func logMultiPartRequestBody(body *bytes.Buffer, log logger.Logger) {
286291
encoding := "none"
287292
if strings.Contains(headers, "base64") || strings.Contains(bodyContent, "base64,") {
288293
encoding = "base64"
289-
} else if strings.Contains(headers, "quoted-printable") {
290-
encoding = "quoted-printable"
291294
}
292295

293296
// Log headers and indicate content is omitted

0 commit comments

Comments
 (0)