Update http_service.dart

This commit is contained in:
Ashita Prasad
2025-02-15 18:21:26 +05:30
parent 2cdacc7d67
commit dc3eded7b2

View File

@@ -10,15 +10,16 @@ import 'http_client_manager.dart';
typedef HttpResponse = http.Response; typedef HttpResponse = http.Response;
Future<(HttpResponse?, Duration?, String?)> request( final httpClientManager = HttpClientManager();
Future<(HttpResponse?, Duration?, String?)> sendHttpRequest(
String requestId, String requestId,
APIType apiType, APIType apiType,
HttpRequestModel requestModel, { HttpRequestModel requestModel, {
SupportedUriSchemes defaultUriScheme = kDefaultUriScheme, SupportedUriSchemes defaultUriScheme = kDefaultUriScheme,
bool noSSL = false, bool noSSL = false,
}) async { }) async {
final clientManager = HttpClientManager(); final client = httpClientManager.createClient(requestId, noSSL: noSSL);
final client = clientManager.createClient(requestId, noSSL: noSSL);
(Uri?, String?) uriRec = getValidRequestUri( (Uri?, String?) uriRec = getValidRequestUri(
requestModel.url, requestModel.url,
@@ -123,14 +124,18 @@ Future<(HttpResponse?, Duration?, String?)> request(
stopwatch.stop(); stopwatch.stop();
return (response, stopwatch.elapsed, null); return (response, stopwatch.elapsed, null);
} catch (e) { } catch (e) {
if (clientManager.wasRequestCancelled(requestId)) { if (httpClientManager.wasRequestCancelled(requestId)) {
return (null, null, kMsgRequestCancelled); return (null, null, kMsgRequestCancelled);
} }
return (null, null, e.toString()); return (null, null, e.toString());
} finally { } finally {
clientManager.closeClient(requestId); httpClientManager.closeClient(requestId);
} }
} else { } else {
return (null, null, uriRec.$2); return (null, null, uriRec.$2);
} }
} }
void cancelHttpRequest(String? requestId) {
httpClientManager.cancelRequest(requestId);
}