@@ -3,39 +3,36 @@ import 'dart:collection';
33import 'package:flutter/foundation.dart' ;
44import 'package:http/http.dart' as http;
55import 'package:http/io_client.dart' ;
6+ import 'package:apidash_core/models/models.dart' ;
67
7- http.Client createHttpClientWithNoSSL () {
8- var ioClient = HttpClient ()
9- ..badCertificateCallback =
10- (X509Certificate cert, String host, int port) => true ;
11- return IOClient (ioClient);
12- }
8+ http.Client createCustomHttpClient ({
9+ bool noSSL = false ,
10+ ProxySettings ? proxySettings,
11+ }) {
12+ if (kIsWeb) {
13+ return http.Client ();
14+ }
1315
14- http.Client createHttpClientWithProxy (
15- String proxyHost,
16- String proxyPort,
17- {String ? proxyUsername,
18- String ? proxyPassword,
19- bool noSSL = false }
20- ) {
2116 var ioClient = HttpClient ();
22-
23- // Configure proxy settings
24- ioClient.findProxy = (uri) {
25- return 'PROXY $proxyHost :$proxyPort ' ;
26- };
2717
28- // Configure proxy authentication if credentials are provided
29- if (proxyUsername != null && proxyPassword != null ) {
30- ioClient.authenticate = (Uri url, String scheme, String ? realm) async {
31- return true ;
32- };
18+ // Configure SSL
19+ if (noSSL) {
20+ ioClient.badCertificateCallback = (X509Certificate cert, String host, int port) => true ;
3321 }
3422
35- // Disable SSL verification if required
36- if (noSSL) {
37- ioClient.badCertificateCallback =
38- (X509Certificate cert, String host, int port) => true ;
23+ // Configure proxy if enabled
24+ if (proxySettings != null ) {
25+ // Set proxy server
26+ ioClient.findProxy = (uri) {
27+ return 'PROXY ${proxySettings .host }:${proxySettings .port }' ;
28+ };
29+
30+ // Configure proxy authentication if credentials are provided
31+ if (proxySettings.username != null && proxySettings.password != null ) {
32+ ioClient.authenticate = (Uri url, String scheme, String ? realm) async {
33+ return true ;
34+ };
35+ }
3936 }
4037
4138 return IOClient (ioClient);
@@ -56,22 +53,12 @@ class HttpClientManager {
5653 http.Client createClient (
5754 String requestId, {
5855 bool noSSL = false ,
59- String ? proxyHost,
60- String ? proxyPort,
61- String ? proxyUsername,
62- String ? proxyPassword,
56+ ProxySettings ? proxySettings,
6357 }) {
64- final client = proxyHost != null && proxyPort != null
65- ? createHttpClientWithProxy (
66- proxyHost,
67- proxyPort,
68- proxyUsername: proxyUsername,
69- proxyPassword: proxyPassword,
70- noSSL: noSSL
71- )
72- : (noSSL && ! kIsWeb)
73- ? createHttpClientWithNoSSL ()
74- : http.Client ();
58+ final client = createCustomHttpClient (
59+ noSSL: noSSL,
60+ proxySettings: proxySettings,
61+ );
7562
7663 _clients[requestId] = client;
7764 return client;
0 commit comments