@@ -106,6 +106,8 @@ pub enum ProxyScheme {
106
106
host : http:: uri:: Authority ,
107
107
} ,
108
108
#[ cfg( feature = "socks" ) ]
109
+ Socks4 { addr : SocketAddr } ,
110
+ #[ cfg( feature = "socks" ) ]
109
111
Socks5 {
110
112
addr : SocketAddr ,
111
113
auth : Option < ( String , String ) > ,
@@ -577,6 +579,16 @@ impl ProxyScheme {
577
579
} )
578
580
}
579
581
582
+ /// Proxy traffic via the specified socket address over SOCKS4
583
+ ///
584
+ /// # Note
585
+ ///
586
+ /// Current SOCKS4 support is provided via blocking IO.
587
+ #[ cfg( feature = "socks" ) ]
588
+ fn socks4 ( addr : SocketAddr ) -> crate :: Result < Self > {
589
+ Ok ( ProxyScheme :: Socks4 { addr } )
590
+ }
591
+
580
592
/// Proxy traffic via the specified socket address over SOCKS5
581
593
///
582
594
/// # Note
@@ -628,6 +640,10 @@ impl ProxyScheme {
628
640
* auth = Some ( header) ;
629
641
}
630
642
#[ cfg( feature = "socks" ) ]
643
+ ProxyScheme :: Socks4 { .. } => {
644
+ panic ! ( "Socks4 is not supported for this method" )
645
+ }
646
+ #[ cfg( feature = "socks" ) ]
631
647
ProxyScheme :: Socks5 { ref mut auth, .. } => {
632
648
* auth = Some ( ( username. into ( ) , password. into ( ) ) ) ;
633
649
}
@@ -643,8 +659,12 @@ impl ProxyScheme {
643
659
* auth = Some ( header_value) ;
644
660
}
645
661
#[ cfg( feature = "socks" ) ]
662
+ ProxyScheme :: Socks4 { .. } => {
663
+ panic ! ( "Socks4 is not supported for this method" )
664
+ }
665
+ #[ cfg( feature = "socks" ) ]
646
666
ProxyScheme :: Socks5 { .. } => {
647
- panic ! ( "Socks is not supported for this method" )
667
+ panic ! ( "Socks5 is not supported for this method" )
648
668
}
649
669
}
650
670
}
@@ -662,6 +682,8 @@ impl ProxyScheme {
662
682
}
663
683
}
664
684
#[ cfg( feature = "socks" ) ]
685
+ ProxyScheme :: Socks4 { .. } => { }
686
+ #[ cfg( feature = "socks" ) ]
665
687
ProxyScheme :: Socks5 { .. } => { }
666
688
}
667
689
@@ -670,7 +692,7 @@ impl ProxyScheme {
670
692
671
693
/// Convert a URL into a proxy scheme
672
694
///
673
- /// Supported schemes: HTTP, HTTPS, (SOCKS5, SOCKS5H if `socks` feature is enabled).
695
+ /// Supported schemes: HTTP, HTTPS, (SOCKS4, SOCKS5, SOCKS5H if `socks` feature is enabled).
674
696
// Private for now...
675
697
fn parse ( url : Url ) -> crate :: Result < Self > {
676
698
use url:: Position ;
@@ -680,7 +702,7 @@ impl ProxyScheme {
680
702
let to_addr = || {
681
703
let addrs = url
682
704
. socket_addrs ( || match url. scheme ( ) {
683
- "socks5" | "socks5h" => Some ( 1080 ) ,
705
+ "socks4" | " socks5" | "socks5h" => Some ( 1080 ) ,
684
706
_ => None ,
685
707
} )
686
708
. map_err ( crate :: error:: builder) ?;
@@ -694,6 +716,8 @@ impl ProxyScheme {
694
716
"http" => Self :: http ( & url[ Position :: BeforeHost ..Position :: AfterPort ] ) ?,
695
717
"https" => Self :: https ( & url[ Position :: BeforeHost ..Position :: AfterPort ] ) ?,
696
718
#[ cfg( feature = "socks" ) ]
719
+ "socks4" => Self :: socks4 ( to_addr ( ) ?) ?,
720
+ #[ cfg( feature = "socks" ) ]
697
721
"socks5" => Self :: socks5 ( to_addr ( ) ?) ?,
698
722
#[ cfg( feature = "socks" ) ]
699
723
"socks5h" => Self :: socks5h ( to_addr ( ) ?) ?,
@@ -715,6 +739,8 @@ impl ProxyScheme {
715
739
ProxyScheme :: Http { .. } => "http" ,
716
740
ProxyScheme :: Https { .. } => "https" ,
717
741
#[ cfg( feature = "socks" ) ]
742
+ ProxyScheme :: Socks4 { .. } => "socks4" ,
743
+ #[ cfg( feature = "socks" ) ]
718
744
ProxyScheme :: Socks5 { .. } => "socks5" ,
719
745
}
720
746
}
@@ -725,6 +751,8 @@ impl ProxyScheme {
725
751
ProxyScheme :: Http { host, .. } => host. as_str ( ) ,
726
752
ProxyScheme :: Https { host, .. } => host. as_str ( ) ,
727
753
#[ cfg( feature = "socks" ) ]
754
+ ProxyScheme :: Socks4 { .. } => panic ! ( "socks4" ) ,
755
+ #[ cfg( feature = "socks" ) ]
728
756
ProxyScheme :: Socks5 { .. } => panic ! ( "socks5" ) ,
729
757
}
730
758
}
@@ -736,6 +764,10 @@ impl fmt::Debug for ProxyScheme {
736
764
ProxyScheme :: Http { auth : _auth, host } => write ! ( f, "http://{host}" ) ,
737
765
ProxyScheme :: Https { auth : _auth, host } => write ! ( f, "https://{host}" ) ,
738
766
#[ cfg( feature = "socks" ) ]
767
+ ProxyScheme :: Socks4 { addr } => {
768
+ write ! ( f, "socks4://{addr}" )
769
+ }
770
+ #[ cfg( feature = "socks" ) ]
739
771
ProxyScheme :: Socks5 {
740
772
addr,
741
773
auth : _auth,
0 commit comments