mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
Refactor
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export 'http_client_manager.dart';
|
||||
export 'http_service.dart';
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user