This commit is contained in:
Ashita Prasad
2024-12-21 10:19:34 +05:30
parent 8fbf8908f5
commit 1df49bd727
7 changed files with 34 additions and 38 deletions

View File

@@ -1,8 +1,15 @@
import 'package:apidash_core/utils/http_request_utils.dart';
import 'dart:io';
import 'dart:collection';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'dart:collection';
import '';
import 'package:http/io_client.dart';
http.Client createHttpClientWithNoSSL() {
var ioClient = HttpClient()
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
return IOClient(ioClient);
}
class HttpClientManager {
static final HttpClientManager _instance = HttpClientManager._internal();
@@ -16,14 +23,16 @@ class HttpClientManager {
HttpClientManager._internal();
http.Client createClient(String requestId,{bool noSSL = false}) {
final client = noSSL && !kIsWeb ? createHttpClientWithNoSSL() :http.Client();
http.Client createClient(
String requestId, {
bool noSSL = false,
}) {
final client =
(noSSL && !kIsWeb) ? createHttpClientWithNoSSL() : http.Client();
_clients[requestId] = client;
return client;
}
void cancelRequest(String? requestId) {
if (requestId != null && _clients.containsKey(requestId)) {
_clients[requestId]?.close();

View File

@@ -9,11 +9,12 @@ import '../utils/utils.dart';
import 'http_client_manager.dart';
typedef HttpResponse = http.Response;
Future<(HttpResponse?, Duration?, String?)> request(
String requestId,
HttpRequestModel requestModel, {
SupportedUriSchemes defaultUriScheme = kDefaultUriScheme,
bool noSSL = false, // Add a parameter to specify SSL-bypass
bool noSSL = false,
}) async {
final clientManager = HttpClientManager();
final client = clientManager.createClient(requestId, noSSL: noSSL);
@@ -73,7 +74,6 @@ Future<(HttpResponse?, Duration?, String?)> request(
return (convertedMultiPartResponse, stopwatch.elapsed, null);
}
}
switch (requestModel.method) {
case HTTPVerb.get:
response = await client.get(requestUrl, headers: headers);

View File

@@ -1,3 +1,2 @@
export 'http_client_manager.dart';
export 'http_service.dart';

View File

@@ -1,18 +1,6 @@
import 'dart:io';
import 'package:collection/collection.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import 'package:seed/seed.dart';
http.Client createHttpClientWithNoSSL() {
var ioClient = HttpClient()
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
return IOClient(ioClient);
}
Map<String, String>? rowsToMap(
List<NameValueModel>? kvRows, {
bool isHeader = false,