File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ dependencies:
16
16
17
17
```
18
18
19
- ### Usage (Example With Dio)
19
+ ### Basic Usage (Example With Dio)
20
20
21
21
``` dart
22
22
import 'package:flutter_system_proxy/flutter_system_proxy.dart';
@@ -36,3 +36,41 @@ var proxy = await FlutterSystemProxy.findProxyFromEnvironment(url);
36
36
};
37
37
var response = await dio.get(url);
38
38
```
39
+
40
+ ### Advanced Usage (Custom Dio Adapter)
41
+
42
+ ``` dart
43
+
44
+ // Create a custom adapter that can help resolve proxy based on urls
45
+ // (This is important as in some senerio there are PAC files which might have different proxy based on different urls)
46
+ class MyAdapter extends HttpClientAdapter {
47
+ final DefaultHttpClientAdapter _adapter = DefaultHttpClientAdapter();
48
+
49
+ @override
50
+ Future<ResponseBody> fetch(RequestOptions options,
51
+ Stream<Uint8List>? requestStream, Future? cancelFuture) async {
52
+ var uri = options.uri;
53
+ var proxy =
54
+ await FlutterSystemProxy.findProxyFromEnvironment(uri.toString()); // This line does the magic
55
+ _adapter.onHttpClientCreate = (HttpClient clinet) {
56
+ clinet.findProxy = (uri) {
57
+ return proxy;
58
+ };
59
+ };
60
+ return _adapter.fetch(options, requestStream, cancelFuture);
61
+ }
62
+
63
+ @override
64
+ void close({bool force = false}) {
65
+ _adapter.close(force: force);
66
+ }
67
+ }
68
+
69
+ // Use a wrapper around getting dio
70
+ void getDio(){
71
+ var dio = Dio();
72
+ dio.httpClientAdapter = MyAdapter();
73
+ return dio;
74
+ }
75
+
76
+ ```
You can’t perform that action at this time.
0 commit comments