|
9 | 9 | "mime/multipart"
|
10 | 10 | "net/http"
|
11 | 11 | "os"
|
| 12 | + "strings" |
12 | 13 | "time"
|
13 | 14 |
|
14 | 15 | "github.com/deploymenttheory/go-api-http-client/authenticationhandler"
|
@@ -193,19 +194,30 @@ func trackUploadProgress(file *os.File, writer io.Writer, totalSize int64, log l
|
193 | 194 | // logRequestBody logs the constructed request body for debugging purposes.
|
194 | 195 | func logRequestBody(body *bytes.Buffer, log logger.Logger) {
|
195 | 196 | bodyBytes := body.Bytes()
|
196 |
| - bodyLen := len(bodyBytes) |
| 197 | + bodyStr := string(bodyBytes) |
| 198 | + firstBoundaryIndex := strings.Index(bodyStr, "---") |
| 199 | + lastBoundaryIndex := strings.LastIndex(bodyStr, "---") |
| 200 | + boundaryLength := 3 // Length of "---" |
| 201 | + trailingCharCount := 20 |
| 202 | + |
| 203 | + if firstBoundaryIndex != -1 && lastBoundaryIndex != -1 && firstBoundaryIndex != lastBoundaryIndex { |
| 204 | + // Content before the first boundary |
| 205 | + preBoundary := bodyStr[:firstBoundaryIndex+boundaryLength] |
| 206 | + // 20 characters after the first boundary |
| 207 | + afterFirstBoundary := bodyStr[firstBoundaryIndex+boundaryLength : firstBoundaryIndex+boundaryLength+trailingCharCount] |
| 208 | + // 20 characters before the last boundary |
| 209 | + beforeLastBoundary := bodyStr[lastBoundaryIndex-trailingCharCount : lastBoundaryIndex] |
| 210 | + // Everything after the last boundary |
| 211 | + postBoundary := bodyStr[lastBoundaryIndex:] |
197 | 212 |
|
198 |
| - if bodyLen > 20 { |
199 |
| - firstPart := string(bodyBytes[:10]) |
200 |
| - lastPart := string(bodyBytes[bodyLen-10:]) |
201 |
| - fullBodyPreview := string(bodyBytes[10 : bodyLen-10]) |
202 | 213 | log.Info("Request body preview",
|
203 |
| - zap.String("first_10_characters", firstPart), |
204 |
| - zap.String("trailing_10_characters", lastPart), |
205 |
| - zap.String("full_body_preview", fullBodyPreview)) |
| 214 | + zap.String("pre_boundary", preBoundary), |
| 215 | + zap.String("after_first_boundary", afterFirstBoundary), |
| 216 | + zap.String("before_last_boundary", beforeLastBoundary), |
| 217 | + zap.String("post_boundary", postBoundary)) |
206 | 218 | } else {
|
207 | 219 | log.Info("Request body preview",
|
208 |
| - zap.String("body", string(bodyBytes))) |
| 220 | + zap.String("body", bodyStr)) |
209 | 221 | }
|
210 | 222 | }
|
211 | 223 |
|
|
0 commit comments