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) {
  if (request) {
    _printRequestHeader(options);
  }
  if (requestHeader) {
    _printMapAsTable(options.queryParameters, header: 'Query Parameters');
    final requestHeaders = <String, dynamic>{};
    requestHeaders.addAll(options.headers);
    requestHeaders['contentType'] = options.contentType?.toString();
    requestHeaders['responseType'] = options.responseType.toString();
    requestHeaders['followRedirects'] = options.followRedirects;
    requestHeaders['connectTimeout'] = options.connectTimeout?.toString();
    requestHeaders['receiveTimeout'] = options.receiveTimeout?.toString();
    _printMapAsTable(requestHeaders, header: 'Headers');
    _printMapAsTable(options.extra, header: 'Extras');
  }
  if (requestBody && options.method != 'GET') {
    final dynamic data = options.data;
    if (data != null) {
      if (data is Map) _printMapAsTable(options.data as Map?, header: 'Body');
      if (data is FormData) {
        // final formDataMap = <String, dynamic>{}
        //   ..addEntries(data.fields)
        //   ..addEntries(data.files);
        // _printMapAsTable(formDataMap, header: 'Form data | ${data.boundary}');
      } else {
        _printBlock(data.toString());
      }
    }
  }
  super.onRequest(options, handler);
}