Redaction
Category: Observability
Source: redaction.dart
Redaction helpers for HTTP debug logging.
Philosophy: allowlist safe header names, mask everything else. Bodies and URLs pass through a deny-pattern regex pass so common API key shapes are caught even if the header allowlist misses them.
Functions
Map<String, String> redactHeaders(Map<String, String> headers)
Returns a redacted copy of [headers].
Header names are compared case-insensitively. Values for allowlisted headers pass through unchanged; everything else becomes ****.
String redactUrl(Uri uri)
Strips sensitive query parameters from [uri] and returns its string form.
We manually rebuild the query string so the literal **** mask appears in the log — using [Uri.replace] would url-encode the asterisks to %2A, which is technically correct but unreadable.
String redactBody(String body, {int maxBytes = 65536})
Redacts common secret patterns in [body] and truncates to [maxBytes].
UTF-8 length is used for the cap. If truncated, a …[truncated N bytes] marker is appended so callers know they saw a partial body.