httpGet function

Future<Response> httpGet(
  1. Uri url, {
  2. Map<String, String>? headers,
  3. bool enableDio = false,
  4. String kWebProxy = '',
})

The default http GET that support Logging

Implementation

Future<http.Response> httpGet(
    Uri url, {
      Map<String, String>? headers,
      bool enableDio = false,
      String kWebProxy = '',
    }) async {
  initProxyClient(url);
  final startTime = DateTime.now();
  if (enableDio) {
    try {
      final res = await Dio().get(url.toString(),
          options: Options(headers: headers, responseType: ResponseType.plain));
      printLog('GET:$url', startTime);
      final response = http.Response(res.toString(), res.statusCode!);
      return response;
    } on DioError catch (e) {
      if (e.response != null) {
        final response =
        http.Response(e.response.toString(), e.response!.statusCode!);
        return response;
      } else {
        // ignore: only_throw_errors
        throw e.message ?? '';
      }
    }
  } else {
    var uri = url;
    if (foundation.kIsWeb) {
      final proxyURL = '$url';
      uri = Uri.parse(proxyURL);
    }
    printLog('♻️ GET:$url', startTime);
    return _makeRequest(http.get(uri, headers: headers));
  }
}