onRequest method

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

Called when the request is about to be sent.

Implementation

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
  final id = _generateId();
  options.extra['debug_id'] = id;

  final entry = DebugLogEntry(
    id: id,
    timestamp: DateTime.now(),
    method: stringToHttpMethod(options.method.toLowerCase()),
    url: options.uri.toString(),
    baseUrl: options.baseUrl,
    requestData: _toMap(options.data),
    queryParameters: options.queryParameters,
  );

  _pendingLogs[id] = entry;
  _controller.addLog(entry);
  handler.next(options);
}