httpPut function

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

The default http PUT that support Logging

Implementation

Future<http.Response> httpPut(Uri url,
    {Map<String, String>? headers,
      Object? body,
      bool enableDio = false}) async {
  final startTime = DateTime.now();
  initProxyClient(url);
  if (enableDio) {
    try {
      final res = await Dio().put(url.toString(),
          options: Options(headers: headers, responseType: ResponseType.plain),
          data: body);
      printLog('🔼 PUT:$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 ?? 'error';
      }
    }
  } else {
    printLog('🔼 PUT:$url', startTime);
    return _makeRequest(http.put(url, headers: headers, body: body));
  }
}