onRequest method

  1. @override
Future<void> onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)

Called when the request is about to be sent.

Implementation

@override
Future<void> onRequest(
    RequestOptions options, RequestInterceptorHandler handler) async {
  final Map<String, dynamic> headers = options.headers;
  final DateTime startTime = DateTime.now();
  // ignore: invalid_use_of_internal_member
  final W3CHeader? w3Header = await _networklogger.getW3CHeader(
      headers, startTime.millisecondsSinceEpoch);
  if (w3Header?.isW3cHeaderFound == false &&
      w3Header?.w3CGeneratedHeader != null) {
    headers['traceparent'] = w3Header?.w3CGeneratedHeader;
  }
  options.headers = headers;
  final NetworkData data = NetworkData(
      startTime: startTime,
      url: options.uri.toString(),
      w3cHeader: w3Header,
      method: options.method);
  _requests[options.hashCode] = data;
  handler.next(options);
}