RedactHeaders returns a flattened copy of h with sensitive values redacted.
(h http.Header)
| 73 | |
| 74 | // RedactHeaders returns a flattened copy of h with sensitive values redacted. |
| 75 | func RedactHeaders(h http.Header) map[string]string { |
| 76 | if h == nil { |
| 77 | return nil |
| 78 | } |
| 79 | |
| 80 | redacted := make(map[string]string, len(h)) |
| 81 | for name, values := range h { |
| 82 | if isSensitiveName(name) { |
| 83 | redacted[name] = RedactedValue |
| 84 | continue |
| 85 | } |
| 86 | redacted[name] = strings.Join(values, ", ") |
| 87 | } |
| 88 | return redacted |
| 89 | } |
| 90 | |
| 91 | // RedactJSONSecrets redacts sensitive JSON values by key name. When |
| 92 | // the input is not valid JSON (truncated body, HTML error page, etc.) |