redactLoggedHeaders method

HttpClientBuilder redactLoggedHeaders(
  1. bool shouldRedact(
    1. String headerName
    )
)

Configures the header redaction for this HTTP client.

Headers matching the provided predicate will have their values redacted in logs.

Example:

services.addHttpClient('MyClient')
  .redactLoggedHeaders((name) =>
    name.toLowerCase() == 'authorization' ||
    name.toLowerCase() == 'x-api-key'
  );

Implementation

HttpClientBuilder redactLoggedHeaders(
  bool Function(String headerName) shouldRedact,
) {
  services.configure<HttpClientFactoryOptions>(
    HttpClientFactoryOptions.new,
    (options) => options.shouldRedactHeaderValue = shouldRedact,
    name: name,
  );
  return this;
}