Documentation
¶
Overview ¶
Package httpdebug logs HTTP request / response traffic for developer-facing debugging while redacting credentials.
Three redaction layers run independently:
- sensitive headers (Authorization, Proxy-Authorization) collapse to a placeholder before any header dump is written;
- URL userinfo (user@ or user:pass@) is stripped from any text run through RedactURLCredentials, covering Location headers and HTML redirect bodies;
- JSON token fields (access_token, id_token, refresh_token, subject_token) — the shapes the STS / OAuth endpoints return — collapse to the placeholder.
The redactors run in that order in BodyPreview. Truncation comes last: if a long JWT or URL password extends past the preview boundary, truncating first would leave the regex's terminator outside the slice and silently leak the secret. Tests in this package pin the order.
Index ¶
Constants ¶
const Placeholder = "***REDACTED***"
Placeholder replaces any redacted value in dumps.
const PreviewBytes = 512
PreviewBytes is the upper bound on the size of a body preview written to the log. Anything beyond is truncated.
Variables ¶
var SensitiveHeaders = map[string]struct{}{
"Authorization": {},
"Proxy-Authorization": {},
}
SensitiveHeaders carries credentials we never want to log verbatim. Stored by canonical key so RedactHeaders can do a single map lookup per header.
Functions ¶
func BodyPreview ¶
BodyPreview returns the first PreviewBytes of body after URL + JSON-token redaction. Redaction MUST happen before truncation: a long JWT or URL password can extend past PreviewBytes, leaving its terminator (closing quote or `@`) outside the preview slice and out of reach of the regexes — truncate-first silently leaks the secret.
When the body contains a packfile, the preview ends just after the PACK signature so the rest of the binary stream doesn't flood the log.
func RedactHeaders ¶
RedactHeaders returns a copy of h with values for SensitiveHeaders replaced by Placeholder. The input is not mutated — callers still need the real headers on the live request/response.
func RedactJSONTokens ¶
RedactJSONTokens replaces JWT values inside a JSON body with Placeholder. Bodies that aren't JSON (or don't carry token fields) pass through unchanged.
func RedactURLCredentials ¶
RedactURLCredentials replaces the userinfo of any http/https URL in s with Placeholder. Safe to run over arbitrary text — header dumps, HTML bodies, log lines.
Types ¶
type RoundTripper ¶
type RoundTripper struct {
Next http.RoundTripper
}
RoundTripper wraps another http.RoundTripper and logs each request/response when debuglog.Enabled returns true. Bodies and sensitive headers are redacted before logging.
When debugging is off, the wrapper is a thin pass-through: no allocations, no body buffering.