mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
Merge pull request #512 from Clasherzz/NO_SSL
feat:Bypass SSL Verification while making requests
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:io';
|
||||
import 'dart:collection';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
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();
|
||||
@@ -13,8 +23,12 @@ class HttpClientManager {
|
||||
|
||||
HttpClientManager._internal();
|
||||
|
||||
http.Client createClient(String requestId) {
|
||||
final client = http.Client();
|
||||
http.Client createClient(
|
||||
String requestId, {
|
||||
bool noSSL = false,
|
||||
}) {
|
||||
final client =
|
||||
(noSSL && !kIsWeb) ? createHttpClientWithNoSSL() : http.Client();
|
||||
_clients[requestId] = client;
|
||||
return client;
|
||||
}
|
||||
|
||||
@@ -14,15 +14,17 @@ Future<(HttpResponse?, Duration?, String?)> request(
|
||||
String requestId,
|
||||
HttpRequestModel requestModel, {
|
||||
SupportedUriSchemes defaultUriScheme = kDefaultUriScheme,
|
||||
bool noSSL = false,
|
||||
}) async {
|
||||
final clientManager = HttpClientManager();
|
||||
final client = clientManager.createClient(requestId);
|
||||
final client = clientManager.createClient(requestId, noSSL: noSSL);
|
||||
|
||||
(Uri?, String?) uriRec = getValidRequestUri(
|
||||
requestModel.url,
|
||||
requestModel.enabledParams,
|
||||
defaultUriScheme: defaultUriScheme,
|
||||
);
|
||||
|
||||
if (uriRec.$1 != null) {
|
||||
Uri requestUrl = uriRec.$1!;
|
||||
Map<String, String> headers = requestModel.enabledHeadersMap;
|
||||
@@ -32,6 +34,7 @@ Future<(HttpResponse?, Duration?, String?)> request(
|
||||
Stopwatch stopwatch = Stopwatch()..start();
|
||||
var isMultiPartRequest =
|
||||
requestModel.bodyContentType == ContentType.formdata;
|
||||
|
||||
if (kMethodsWithBody.contains(requestModel.method)) {
|
||||
var requestBody = requestModel.body;
|
||||
if (requestBody != null && !isMultiPartRequest) {
|
||||
|
||||
Reference in New Issue
Block a user