@@ -3,39 +3,36 @@ import 'dart:collection';
3
3
import 'package:flutter/foundation.dart' ;
4
4
import 'package:http/http.dart' as http;
5
5
import 'package:http/io_client.dart' ;
6
+ import 'package:apidash_core/models/models.dart' ;
6
7
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
+ }
13
15
14
- http.Client createHttpClientWithProxy (
15
- String proxyHost,
16
- String proxyPort,
17
- {String ? proxyUsername,
18
- String ? proxyPassword,
19
- bool noSSL = false }
20
- ) {
21
16
var ioClient = HttpClient ();
22
-
23
- // Configure proxy settings
24
- ioClient.findProxy = (uri) {
25
- return 'PROXY $proxyHost :$proxyPort ' ;
26
- };
27
17
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 ;
33
21
}
34
22
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
+ }
39
36
}
40
37
41
38
return IOClient (ioClient);
@@ -56,22 +53,12 @@ class HttpClientManager {
56
53
http.Client createClient (
57
54
String requestId, {
58
55
bool noSSL = false ,
59
- String ? proxyHost,
60
- String ? proxyPort,
61
- String ? proxyUsername,
62
- String ? proxyPassword,
56
+ ProxySettings ? proxySettings,
63
57
}) {
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
+ );
75
62
76
63
_clients[requestId] = client;
77
64
return client;
0 commit comments