onRequest method
Called when the request is about to be sent.
Implementation
@override
Future<void> onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) async {
if (!enabled) return handler.next(options);
final registry = DebugEnvironments.instance;
final group = environments.isNotEmpty ? environments : registry.global;
if (group.isNotEmpty) {
await registry.ready;
final baseUrl = registry.resolve(group, options.baseUrl);
if (baseUrl != null) options.baseUrl = baseUrl;
}
if (client != null) options.extra[clientKey] = client;
_guard(() => debug.addRequest(options), 'addRequest');
if (printToConsole) {
debugPrint('🐙 REQUEST [${options.method}] ${_safeUrl(options.uri)}');
if (options.headers.isNotEmpty) {
debugPrint(
' HEADERS: ${LogFormatter.normalizeHeaders(options.headers, redact: redactSensitiveHeaders)}',
);
}
if (options.data != null) {
debugPrint(
' BODY: ${_truncate(LogFormatter.encode(_safe(options.data)))}',
);
}
}
handler.next(options);
}