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) {
  Map<String, dynamic>? parameters;
  final url = options.uri.path;
  final method = options.method;
  CancelToken? cancelToken = options.cancelToken;
  Map<String, dynamic> headers = options.headers;
  if (headers[BaseHttpConstant.HEADERS_NETWORK_DEBOUNCE_KEY] != null && headers[BaseHttpConstant.HEADERS_NETWORK_DEBOUNCE_KEY] == 'true') {
    //需要处理请求防抖去重
    parameters = _generateParameters(method, options);
    _handleNetworkDebounce(url, method, parameters, cancelToken, options, handler);
  } else {
    super.onRequest(options, handler);
  }
}