Skip to content

Commit 9b9ff08

Browse files
author
Jamario Rankins
committed
Added doc for Redact and Added empty string case for header
1 parent 867ff5e commit 9b9ff08

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

debug/debug.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func DumpRequest(req *http.Request) {
4848
temp := req.Header.Get("Authorization")
4949

5050
if !UnmaskAPIKey {
51-
req.Header.Set("Authorization", "Bearer "+utils.Redact(strings.Split(temp, " ")[1]))
51+
if token := strings.Split(temp, " ")[1]; token != "" {
52+
req.Header.Set("Authorization", "Bearer "+utils.Redact(token))
53+
}
5254
}
5355

5456
dump, err := httputil.DumpRequest(req, req.ContentLength > 0)

utils/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package utils
22

33
import "strings"
44

5+
/*
6+
Redact masks the given token by replacing part of the string with *
7+
*/
58
func Redact(token string) string {
69
str := token[4 : len(token)-3]
710
redaction := strings.Repeat("*", len(str))

0 commit comments

Comments
 (0)