httpGet function
The default http GET that support Logging
Implementation
Future<http.Response> httpGet(
Uri uri, {
Map<String, String>? headers,
bool enableDio = false,
bool refreshCache = false,
}) async {
initProxyClient(MultiSite.mainSiteUrl ?? uri);
final startTime = DateTime.now();
var url = HttpClientSetting.settingProxy(uri);
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 DioException 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 {
if (refreshCache) {
url = url.replace(queryParameters: {
...url.queryParameters,
'refresh': '${DateTime.now().millisecondsSinceEpoch}'
});
}
var uri = url;
if (foundation.kIsWeb) {
final proxyURL = '$url';
uri = Uri.parse(proxyURL);
}
var response = await _makeRequest(http.get(uri, headers: headers));
printLog('♻️ GET:$url', startTime);
return response;
}
}