Skip to content

V0.1.50 dev #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions httpclient/multipartrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
}

// Log the constructed request body for debugging
logRequestBody(body, log)
logMultiPartRequestBody(body, log)

// Construct the full URL for the API endpoint.
url := c.APIHandler.ConstructAPIResourceEndpoint(endpoint, log)
Expand All @@ -84,9 +84,6 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
headerHandler.SetRequestHeaders(endpoint)
headerHandler.LogHeaders(c.clientConfig.ClientOptions.Logging.HideSensitiveData)

// Log headers for debugging
logHeaders(req, log)

req = req.WithContext(ctx)

startTime := time.Now()
Expand Down Expand Up @@ -269,8 +266,8 @@ func logUploadProgress(totalSize int64, log logger.Logger) func(int64) {
}
}

// logRequestBody logs the constructed request body for debugging purposes.
func logRequestBody(body *bytes.Buffer, log logger.Logger) {
// logMultiPartRequestBody logs the constructed request body for debugging purposes.
func logMultiPartRequestBody(body *bytes.Buffer, log logger.Logger) {
bodyBytes := body.Bytes()
bodyStr := string(bodyBytes)

Expand All @@ -292,11 +289,12 @@ func logRequestBody(body *bytes.Buffer, log logger.Logger) {
continue // Skip the last boundary marker or empty parts
}
if strings.Contains(part, "Content-Disposition: form-data; name=\"file\"") {
// If it's a file part, only log the headers
// If it's a file part, log headers and indicate content is omitted
headersEndIndex := strings.Index(part, "\r\n\r\n")
if headersEndIndex != -1 {
headers := part[:headersEndIndex]
loggedParts = append(loggedParts, headers+"\r\n\r\n<file content omitted>\r\n")
fileMeta := part[headersEndIndex+4 : len(part)-2] // Extract the file metadata portion
loggedParts = append(loggedParts, headers+"\r\n\r\n<file content omitted>\r\n"+fileMeta)
} else {
loggedParts = append(loggedParts, part)
}
Expand All @@ -311,12 +309,3 @@ func logRequestBody(body *bytes.Buffer, log logger.Logger) {

log.Info("Request body preview", zap.String("body", loggedBody))
}

// logHeaders logs the request headers for debugging purposes.
func logHeaders(req *http.Request, log logger.Logger) {
for key, values := range req.Header {
for _, value := range values {
log.Info("Request header", zap.String("key", key), zap.String("value", value))
}
}
}
Loading