mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
Update http_service.dart
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user