redactHttpRecord static method
Return record with its hidden request headers masked and the hidden
keys of a JSON or form-encoded request or response body masked, then,
when a redactor is registered, every text field run through it.
Any other body is kept as is, and so is a body with nothing to hide
(byte for byte, so its formatting survives). Returns record itself
when nothing was masked and no redactor is registered. Never throws on
a malformed body. Returns null, the record dropped, when the redactor
throws.
Implementation
static HttpRequestRecord? redactHttpRecord(HttpRequestRecord record) {
final HttpRequestRecord keyed = _redactHttpKeys(record);
final String Function(String)? redact = _guardedRedactor();
if (redact == null) return keyed;
return _dropOnRedactorFailure(
() => _markRedacted(
HttpRequestRecord(
url: redact(keyed.url),
method: redact(keyed.method),
statusCode: keyed.statusCode,
durationMs: keyed.durationMs,
isError: keyed.isError,
timestamp: keyed.timestamp,
requestHeaders: keyed.requestHeaders?.map(
(String name, String value) =>
MapEntry<String, String>(name, redact(value)),
),
requestBody: _text(keyed.requestBody, redact),
responseBody: _text(keyed.responseBody, redact),
attributedHeuristically: keyed.attributedHeuristically,
requestId: _text(keyed.requestId, redact),
startUs: keyed.startUs,
endUs: keyed.endUs,
atUs: keyed.atUs,
interactionId: _text(keyed.interactionId, redact),
linkedBy: _text(keyed.linkedBy, redact),
),
),
);
}