send method

  1. @override
Future<StreamedResponse> send(
  1. BaseRequest request
)

Overrides the send method to intercept HTTP requests.

Adds custom headers, logs request and response details in debug mode, and then delegates the actual request to the inner _inner client.

Returns a http.StreamedResponse which can be parsed further.

Implementation

@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
  // 🛡️ Add your custom headers here if needed
  request.headers.addAll(request.headers); // You can customize this logic

  final response = await _inner.send(request);

  // 🧾 Debug logging of request and response details
  if (kDebugMode) {
    NetworkLogger.shared.d('➡️ ${request.method} ${request.url}');
    NetworkLogger.shared.d('Headers: ${request.headers}');
    if (request is http.Request) {
      NetworkLogger.shared.d('Body: ${request.body}');
    }
    NetworkLogger.shared.d('response: $response');
  }

  return response;
}