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 {
  final startTime = DateTime.now();
  initProxyClient(url);
  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 {
    // ignore: prefer_typing_uninitialized_variables
    var response;
    var uri = url;
    if (foundation.kIsWeb) {
      final proxyURL = '$url';
      uri = Uri.parse(proxyURL);
    }

    response = await http.get(uri, headers: headers);
    printLog('♻️ GET:$url', startTime);

    return response;
  }
}