ispectify_http 7.0.0-dev2 copy "ispectify_http: ^7.0.0-dev2" to clipboard
ispectify_http: ^7.0.0-dev2 copied to clipboard

http_interceptor integration for ISpect with correlated HTTP request, response, error, timing, and redacted payload logs.

ispectify_http is an http_interceptor interceptor for the ISpect toolkit. It captures requests made through the package:http client, pairs them into transactions, and redacts sensitive data before logging.

  • Request, response, and error capture with headers, body, status, and duration.
  • Redaction of auth headers, tokens, PII, and financial data. On by default.
  • Works with any InterceptedClient from http_interceptor.

Install #

dependencies:
  http: ^1.0.0
  http_interceptor: ^2.0.0
  ispectify: ^7.0.0-dev2
  ispectify_http: ^7.0.0-dev2

Quick start #

import 'package:http_interceptor/http_interceptor.dart' as http_interceptor;
import 'package:ispect/ispect.dart';
import 'package:ispectify_http/ispectify_http.dart';

final client = http_interceptor.InterceptedClient.build(interceptors: []);

ISpect.run(
  () => runApp(const MyApp()),
  logger: logger,
  onInit: () {
    client.interceptors.add(
      ISpectHttpInterceptor(
        logger: logger,
        settings: const ISpectHttpInterceptorSettings(
          printRequestHeaders: true,
          printResponseHeaders: true,
        ),
      ),
    );
  },
);

Register ISpectHttpInterceptor last in the interceptors list. Request/response correlation is keyed on the BaseRequest instance, and http_interceptor lets each interceptor return a new request object. If an interceptor registered after it rebuilds the request, the response can't be matched and stays "Pending".

Settings #

ISpectHttpInterceptorSettings mirrors the Dio version. Headers and bodies are omitted by default, and enableRedaction defaults to true.

const settings = ISpectHttpInterceptorSettings(
  logRequests: true,
  logResponses: true,
  printRequestHeaders: true,
  printRequestData: true,
  printResponseHeaders: false,
  printResponseData: true,
  enableRedaction: true,
);

Preset factories and a builder are also available. See ISpectHttpInterceptorSettingsBuilder for the development(), staging(), and production() presets.

logRequests and logResponses control whether routine records are retained; the production preset disables both and keeps redacted errors. The print* flags explicitly opt bodies, headers, or messages into retained console and metadata fields. The development preset enables verbose payload capture while keeping redaction on. Use the concrete settings copyWith or builder for these retention controls; the shared base configure helper retains its legacy-compatible field set.

Data redaction #

Sensitive data is masked before it reaches logs or observers. Redaction is on by default. The built-in rules cover auth headers, tokens, passwords, API keys, cookies, common PII (SSN, passport, driver's license), financial data (credit cards, IBAN), and phone numbers.

The default policy is a single source of truth. Configure it once and core logs, traces, persistence, network and database adapters, BLoC and Riverpod observers, supported exports, clipboard helpers, and cURL generation resolve it when each diagnostic operation runs.

Redaction works best paired with focused capture. Keep body and header logging off unless you actually need the payload, and register project-specific keys for the business identifiers only your application understands.

Global configuration #

import 'package:ispectify/ispectify.dart';

ISpectRedaction.configure(
  service: RedactionService(
    additionalSensitiveKeys: {
      'x-custom-secret',
      'internal_token',
    },
    additionalSensitiveKeyPatterns: [
      RegExp(r'my_app_secret_\w+', caseSensitive: false),
    ],
    fullyMaskedKeys: {'filename'},
    placeholder: '***',
    visibleEdgeLength: 3,
  ),
);

additionalSensitiveKeys and additionalSensitiveKeyPatterns extend the built-in policy. Use sensitiveKeys or sensitiveKeyPatterns only when you intentionally want to replace the corresponding defaults:

final replacementPolicy = RedactionService(
  sensitiveKeys: {
    'x-custom-secret',
    'internal_token',
  },
  sensitiveKeyPatterns: [
    RegExp(r'my_app_secret_\w+', caseSensitive: false),
  ],
);

Flutter apps can pass the same policy as ISpect.run(redactionService: ...); ISpect.dispose() restores the policy that was active before that run. An explicit RedactionService supplied to one integration stays local and takes precedence over the global policy. Existing integrations without an explicit service pick up later global reconfiguration. The policy is scoped to the current Dart isolate.

Local exceptions #

final redactor = RedactionService(
  ignoredKeys: {'mobile', 'platform_token'},
  ignoredValues: {'<test-token>', 'public-api-key'},
);

Disabling #

ISpectRedaction.configure(enabled: false) is the global content-masking opt-out. Each interceptor also accepts enableRedaction: false on its settings object for a local opt-out. Size limits, non-executing snapshots, private-storage checks, and the compile-time ISPECT_ENABLED gate remain enforced.

Only disable redaction in isolated local or deterministic test environments. Exported sessions and observer events should be handled according to the data they contain.

Custom redactor:

ISpectHttpInterceptor(
  logger: logger,
  redactor: RedactionService(
    additionalSensitiveKeys: {'x-internal-token'},
  ),
);

The ISpect toolkit #

ISpect is a modular monorepo. Pick the packages your project needs. Each one works on its own.

Package What it does
ispect Flutter UI: debug panel, log viewer, navigation observer, inspector integration.
ispect_layout Visual layout inspector with sizes, constraints, decorations, compare mode, and a color picker.
ispectify Pure-Dart logging core: typed log entries, filtering, tracing, observers.
ispectify_dio Dio HTTP interceptor with automatic redaction.
ispectify_http http package interceptor with automatic redaction.
ispectify_ws Provider-agnostic WebSocket capture (any client) with automatic redaction.
ispectify_db Database operation tracing for SQL, ORMs, and KV stores.
ispectify_bloc BLoC event, state, transition, and error observer.
ispectify_riverpod Riverpod provider add, update, dispose, and failure observer.

Contributing #

Contributions are welcome. See CONTRIBUTING.md for guidelines, and open issues or pull requests at the ISpect repository.

License #

MIT. See LICENSE.


0
likes
150
points
3.64k
downloads

Documentation

API reference

Publisher

verified publishershodev.live

Weekly Downloads

http_interceptor integration for ISpect with correlated HTTP request, response, error, timing, and redacted payload logs.

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

http, http_interceptor, http_parser, ispectify

More

Packages that depend on ispectify_http