Skip to content

Commit

Permalink
Merge pull request #206 from deploymenttheory/v0.1.50-dev
Browse files Browse the repository at this point in the history
V0.1.50 dev
  • Loading branch information
ShocOne authored Jun 5, 2024
2 parents a8b80bf + 128b8bc commit a4a91e1
Showing 1 changed file with 6 additions and 17 deletions.
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))
}
}
}

0 comments on commit a4a91e1

Please sign in to comment.