File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ pnet_datalink = "0.35.0"
4848[target .'cfg(target_os = "macos")' .dependencies ]
4949system-configuration = { version = " 0.6.1" , optional = true }
5050
51+ [target .'cfg(windows)' .dependencies ]
52+ windows-registry = { version = " 0.4" , optional = true }
53+
5154[features ]
5255default = []
5356
@@ -68,7 +71,7 @@ full = [
6871client = [" hyper/client" , " dep:tracing" , " dep:futures-channel" , " dep:tower-service" ]
6972client-legacy = [" client" , " dep:socket2" , " tokio/sync" , " dep:libc" ]
7073client-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 " ]
7275
7376server = [" hyper/server" ]
7477server-auto = [" server" , " http1" , " http2" ]
Original file line number Diff line number Diff line change @@ -242,6 +242,9 @@ impl Builder {
242242 #[ cfg( all( feature = "client-proxy-system" , target_os = "macos" ) ) ]
243243 mac:: with_system ( & mut builder) ;
244244
245+ #[ cfg( all( feature = "client-proxy-system" , windows) ) ]
246+ win:: with_system ( & mut builder) ;
247+
245248 builder
246249 }
247250
@@ -638,6 +641,41 @@ mod mac {
638641 }
639642}
640643
644+ #[ cfg( feature = "client-proxy-system" ) ]
645+ #[ cfg( windows) ]
646+ mod win {
647+ pub ( super ) fn with_system ( builder : & mut super :: Builder ) {
648+ let settings = if let Ok ( settings) = windows_registry:: CURRENT_USER
649+ . open ( "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Internet Settings" )
650+ {
651+ settings
652+ } else {
653+ return ;
654+ } ;
655+
656+ if settings. get_u32 ( "ProxyEnable" ) . unwrap_or ( 0 ) == 0 {
657+ return ;
658+ }
659+
660+ if builder. http . is_empty ( ) {
661+ if let Ok ( val) = settings. get_string ( "ProxyServer" ) {
662+ builder. http = val;
663+ }
664+ }
665+
666+ if builder. no . is_empty ( ) {
667+ if let Ok ( val) = settings. get_string ( "ProxyOverride" ) {
668+ builder. no = val
669+ . split ( ';' )
670+ . map ( |s| s. trim ( ) )
671+ . collect :: < Vec < & str > > ( )
672+ . join ( "," )
673+ . replace ( "*." , "" ) ;
674+ }
675+ }
676+ }
677+ }
678+
641679#[ cfg( test) ]
642680mod tests {
643681 use super :: * ;
You can’t perform that action at this time.
0 commit comments