onRequest method

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

Emits a 'request' debug event containing the full request context.

The data map includes the HTTP method, URL, headers, query parameters, request body, content type, response type, and configured timeouts. Forwards the request to the next handler after emitting.

Implementation

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
  onDebug(
    event: 'request',
    message: '${options.method} ${options.uri}',
    data: {
      'method': options.method,
      'url': options.uri.toString(),
      'headers': options.headers,
      'queryParameters': options.queryParameters,
      'body': options.data,
      'contentType': options.contentType,
      'responseType': options.responseType.toString(),
      'connectTimeout': options.connectTimeout?.toString(),
      'receiveTimeout': options.receiveTimeout?.toString(),
    },
  );

  super.onRequest(options, handler);
}