|
|
|
|
@@ -8,7 +8,8 @@
|
|
|
|
|
/// - Retry logic
|
|
|
|
|
library;
|
|
|
|
|
|
|
|
|
|
import 'package:curl_logger_dio_interceptor/curl_logger_dio_interceptor.dart';
|
|
|
|
|
import 'dart:developer' as developer;
|
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
|
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
|
|
|
|
|
import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart';
|
|
|
|
|
@@ -238,6 +239,87 @@ class DioClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Custom Curl Logger Interceptor
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
/// Custom Curl Logger that uses debugPrint instead of print
|
|
|
|
|
class CustomCurlLoggerInterceptor extends Interceptor {
|
|
|
|
|
@override
|
|
|
|
|
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
|
|
|
|
final curl = _cURLRepresentation(options);
|
|
|
|
|
// debugPrint(
|
|
|
|
|
// '╔╣ CURL Request ╠══════════════════════════════════════════════════',
|
|
|
|
|
// );
|
|
|
|
|
// debugPrint(curl);
|
|
|
|
|
// debugPrint(
|
|
|
|
|
// '╚═════════════════════════════════════════════════════════════════',
|
|
|
|
|
// );
|
|
|
|
|
// Also log to dart:developer for better filtering in DevTools
|
|
|
|
|
developer.log(curl, name: 'DIO_CURL', time: DateTime.now());
|
|
|
|
|
handler.next(options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String _cURLRepresentation(RequestOptions options) {
|
|
|
|
|
final components = ['curl --location'];
|
|
|
|
|
|
|
|
|
|
// Add method
|
|
|
|
|
if (options.method.toUpperCase() != 'GET') {
|
|
|
|
|
components.add('-X ${options.method}');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add headers (INCLUDING Cookie this time!)
|
|
|
|
|
options.headers.forEach((key, value) {
|
|
|
|
|
// Escape single quotes in header values
|
|
|
|
|
final escapedValue = value.toString().replaceAll("'", "'\\''");
|
|
|
|
|
components.add("--header '$key: $escapedValue'");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add data with proper JSON formatting
|
|
|
|
|
if (options.data != null) {
|
|
|
|
|
if (options.data is FormData) {
|
|
|
|
|
components.add('--data-binary [FormData]');
|
|
|
|
|
} else {
|
|
|
|
|
// Convert data to proper JSON string
|
|
|
|
|
String jsonData;
|
|
|
|
|
if (options.data is Map || options.data is List) {
|
|
|
|
|
// Use dart:convert to properly encode JSON
|
|
|
|
|
jsonData = _jsonEncode(options.data);
|
|
|
|
|
} else {
|
|
|
|
|
jsonData = options.data.toString();
|
|
|
|
|
}
|
|
|
|
|
// Escape single quotes for shell
|
|
|
|
|
final escapedData = jsonData.replaceAll("'", "'\\''");
|
|
|
|
|
components.add("--data '$escapedData'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add URL
|
|
|
|
|
final uri = options.uri.toString();
|
|
|
|
|
components.add("'$uri'");
|
|
|
|
|
|
|
|
|
|
return components.join(' \\\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Simple JSON encoder (without importing dart:convert in this file)
|
|
|
|
|
String _jsonEncode(dynamic data) {
|
|
|
|
|
if (data == null) return 'null';
|
|
|
|
|
if (data is String) return '"${data.replaceAll('"', r'\"')}"';
|
|
|
|
|
if (data is num || data is bool) return data.toString();
|
|
|
|
|
if (data is List) {
|
|
|
|
|
final items = data.map((e) => _jsonEncode(e)).join(',');
|
|
|
|
|
return '[$items]';
|
|
|
|
|
}
|
|
|
|
|
if (data is Map) {
|
|
|
|
|
final pairs = data.entries
|
|
|
|
|
.map((e) => '"${e.key}":${_jsonEncode(e.value)}')
|
|
|
|
|
.join(',');
|
|
|
|
|
return '{$pairs}';
|
|
|
|
|
}
|
|
|
|
|
return data.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Retry Interceptor
|
|
|
|
|
// ============================================================================
|
|
|
|
|
@@ -383,8 +465,9 @@ Future<Dio> dio(Ref ref) async {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
// Add interceptors in order
|
|
|
|
|
// 1. Curl interceptor (first to log cURL commands)
|
|
|
|
|
..interceptors.add(CurlLoggerDioInterceptor())
|
|
|
|
|
// 1. Custom Curl interceptor (first to log cURL commands)
|
|
|
|
|
// Uses debugPrint and developer.log for better visibility
|
|
|
|
|
..interceptors.add(CustomCurlLoggerInterceptor())
|
|
|
|
|
// 2. Logging interceptor
|
|
|
|
|
..interceptors.add(ref.watch(loggingInterceptorProvider))
|
|
|
|
|
// 3. Auth interceptor (add tokens to requests)
|
|
|
|
|
|