@@ -75,15 +75,9 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
7575 log .Error ("Failed to create HTTP request" , zap .Error (err ))
7676 return nil , err
7777 }
78- req .Header .Set ("Content-Type" , contentType )
79- req .Header .Set ("Accept" , "application/json" )
8078
81- // Apply custom cookies and headers
82- cookiejar .ApplyCustomCookies (req , c .clientConfig .ClientOptions .Cookies .CustomCookies , log )
83-
84- headerHandler := headers .NewHeaderHandler (req , c .Logger , c .APIHandler , c .AuthTokenHandler )
85- headerHandler .SetRequestHeaders (endpoint )
86- headerHandler .LogHeaders (c .clientConfig .ClientOptions .Logging .HideSensitiveData )
79+ // Apply common headers
80+ applyCommonHeaders (req , contentType , endpoint , c )
8781
8882 req = req .WithContext (ctx )
8983
@@ -145,10 +139,7 @@ func addFilePart(writer *multipart.Writer, fieldName, filePath string, contentTy
145139 contentType = ct
146140 }
147141
148- header := textproto.MIMEHeader {}
149- header .Set ("Content-Disposition" , fmt .Sprintf (`form-data; name="%s"; filename="%s"` , fieldName , filepath .Base (filePath )))
150- header .Set ("Content-Type" , contentType )
151- header .Set ("Content-Transfer-Encoding" , "base64" )
142+ header := CustomFormDataHeader (fieldName , filepath .Base (filePath ), contentType , headersMap [fieldName ])
152143
153144 part , err := writer .CreatePart (header )
154145 if err != nil {
@@ -193,6 +184,7 @@ func CustomFormDataHeader(fieldname, filename, contentType string, customHeaders
193184 header := textproto.MIMEHeader {}
194185 header .Set ("Content-Disposition" , fmt .Sprintf (`form-data; name="%s"; filename="%s"` , fieldname , filename ))
195186 header .Set ("Content-Type" , contentType )
187+ header .Set ("Content-Transfer-Encoding" , "base64" )
196188 for key , values := range customHeaders {
197189 for _ , value := range values {
198190 header .Add (key , value )
@@ -327,3 +319,16 @@ func logMultiPartRequestBody(body *bytes.Buffer, log logger.Logger) {
327319
328320 log .Info ("Request body preview" , zap .String ("body" , loggedBody ))
329321}
322+
323+ // applyCommonHeaders sets common headers for the request
324+ func applyCommonHeaders (req * http.Request , contentType string , endpoint string , c * Client ) {
325+ req .Header .Set ("Content-Type" , contentType )
326+ req .Header .Set ("Accept" , "application/json" )
327+
328+ // Apply custom cookies and headers
329+ cookiejar .ApplyCustomCookies (req , c .clientConfig .ClientOptions .Cookies .CustomCookies , c .Logger )
330+
331+ headerHandler := headers .NewHeaderHandler (req , c .Logger , c .APIHandler , c .AuthTokenHandler )
332+ headerHandler .SetRequestHeaders (endpoint )
333+ headerHandler .LogHeaders (c .clientConfig .ClientOptions .Logging .HideSensitiveData )
334+ }
0 commit comments