Skip to content

Commit 6f8d6be

Browse files
committed
adjust client request debug print
1 parent 8f5fa41 commit 6f8d6be

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ coverage.txt
3333

3434
# Go workspace file
3535
go.work
36+
37+
# Log files
38+
*.log

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test:
2-
go test -tags='unit integration' -failfast -count=1 -v -timeout 350m -coverprofile=coverage.txt `go list ./... | egrep -v 'examples|sms'`
2+
go test -tags='unit integration' -failfast -count=1 -v -timeout 350m -coverprofile=coverage.txt `go list ./... | egrep -v 'examples|sms'` | tee -a test.log
33

44
unittest:
55
go test -tags=unit -failfast -count=1 -v -coverprofile=coverage.txt `go list ./... | egrep -v 'examples|sms'`

client/client.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ func newRequest(ctx context.Context, method, reqUrl string, headers http.Header,
9494
}
9595
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
9696

97-
var hasBody = DeepDebugInfo
97+
var (
98+
hasBody = DeepDebugInfo
99+
contentType = req.Header.Get("Content-Type")
100+
)
98101
switch {
99102
case
100-
req.Method == "POST" && req.Header.Get("Content-Type") != "application/json",
101-
req.Header.Get("Content-Type") == "application/octet-stream":
103+
contentType == "" || contentType == "application/octet-stream",
104+
(req.Method == "POST" || req.Method == "PUT" || req.Method == "PATCH") && contentType != "application/json":
102105
hasBody = false
103106
}
104107

internal/clientv2/interceptor_debug.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ func (interceptor *debugInterceptor) printRequest(label string, req *http.Reques
121121

122122
info := label + " request:\n"
123123

124-
var hasBody = IsPrintRequestBody()
124+
var (
125+
hasBody = IsPrintRequestBody()
126+
contentType = req.Header.Get("Content-Type")
127+
)
125128
switch {
126129
case
127-
req.Method == "POST" && req.Header.Get("Content-Type") != "application/json",
128-
req.Header.Get("Content-Type") == "application/octet-stream":
130+
contentType == "" || contentType == "application/octet-stream",
131+
(req.Method == "POST" || req.Method == "PUT" || req.Method == "PATCH") && contentType != "application/json":
129132
hasBody = false
130133
}
131134

0 commit comments

Comments
 (0)