File tree 2 files changed +44
-1
lines changed
2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ pnet_datalink = "0.35.0"
48
48
[target .'cfg(target_os = "macos")' .dependencies ]
49
49
system-configuration = { version = " 0.6.1" , optional = true }
50
50
51
+ [target .'cfg(windows)' .dependencies ]
52
+ windows-registry = { version = " 0.4" , optional = true }
53
+
51
54
[features ]
52
55
default = []
53
56
@@ -68,7 +71,7 @@ full = [
68
71
client = [" hyper/client" , " dep:tracing" , " dep:futures-channel" , " dep:tower-service" ]
69
72
client-legacy = [" client" , " dep:socket2" , " tokio/sync" , " dep:libc" ]
70
73
client-proxy = [" client" , " dep:base64" , " dep:ipnet" , " dep:percent-encoding" ]
71
- client-proxy-system = [" dep:system-configuration" ]
74
+ client-proxy-system = [" dep:system-configuration" , " dep:windows-registry " ]
72
75
73
76
server = [" hyper/server" ]
74
77
server-auto = [" server" , " http1" , " http2" ]
Original file line number Diff line number Diff line change @@ -242,6 +242,9 @@ impl Builder {
242
242
#[ cfg( all( feature = "client-proxy-system" , target_os = "macos" ) ) ]
243
243
mac:: with_system ( & mut builder) ;
244
244
245
+ #[ cfg( all( feature = "client-proxy-system" , windows) ) ]
246
+ win:: with_system ( & mut builder) ;
247
+
245
248
builder
246
249
}
247
250
@@ -638,6 +641,43 @@ mod mac {
638
641
}
639
642
}
640
643
644
+ #[ cfg( feature = "client-proxy-system" ) ]
645
+ #[ cfg( windows) ]
646
+ mod win {
647
+ use windows_registry:: CURRENT_USER ;
648
+
649
+ pub ( super ) fn with_system ( builder : & mut super :: Builder ) {
650
+ let settings = if let Ok ( settings) = windows_registry:: CURRENT_USER
651
+ . open ( "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Internet Settings" )
652
+ {
653
+ settings
654
+ } else {
655
+ return ;
656
+ } ;
657
+
658
+ if settings. get_u32 ( "ProxyEnable" ) . unwrap_or ( 0 ) == 0 {
659
+ return ;
660
+ }
661
+
662
+ if builder. http . is_empty ( ) {
663
+ if let Ok ( val) = settings. get_string ( "ProxyServer" ) {
664
+ builder. http = val;
665
+ }
666
+ }
667
+
668
+ if builder. no . is_empty ( ) {
669
+ if let Ok ( val) = settings. get_string ( "" ) {
670
+ builder. no = value
671
+ . split ( ';' )
672
+ . map ( |s| s. trim ( ) )
673
+ . collect :: < Vec < & str > > ( )
674
+ . join ( "," )
675
+ . replace ( "*." , "" ) ;
676
+ }
677
+ }
678
+ }
679
+ }
680
+
641
681
#[ cfg( test) ]
642
682
mod tests {
643
683
use super :: * ;
You can’t perform that action at this time.
0 commit comments