@@ -60,58 +60,62 @@ where
60
60
fn call ( & mut self , dst : Uri ) -> Self :: Future {
61
61
// dst.scheme() would need to derive Eq to be matchable;
62
62
// use an if cascade instead
63
- let scheme = match dst. scheme ( ) {
64
- Some ( scheme) => scheme,
63
+ match dst. scheme ( ) {
64
+ Some ( scheme) if scheme == & http:: uri:: Scheme :: HTTP => {
65
+ let future = self . http . call ( dst) ;
66
+ return Box :: pin ( async move {
67
+ Ok ( MaybeHttpsStream :: Http ( future. await . map_err ( Into :: into) ?) )
68
+ } ) ;
69
+ }
70
+ Some ( scheme) if scheme != & http:: uri:: Scheme :: HTTPS => {
71
+ let message = format ! ( "unsupported scheme {scheme}" ) ;
72
+ return Box :: pin ( async move {
73
+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , message) . into ( ) )
74
+ } ) ;
75
+ }
76
+ Some ( _) => { }
65
77
None => {
66
78
return Box :: pin ( async move {
67
79
Err ( io:: Error :: new ( io:: ErrorKind :: Other , "missing scheme" ) . into ( ) )
68
80
} )
69
81
}
70
82
} ;
71
83
72
- if scheme == & http:: uri:: Scheme :: HTTP && !self . force_https {
73
- let future = self . http . call ( dst) ;
74
- Box :: pin ( async move { Ok ( MaybeHttpsStream :: Http ( future. await . map_err ( Into :: into) ?) ) } )
75
- } else if scheme == & http:: uri:: Scheme :: HTTPS {
76
- let cfg = self . tls_config . clone ( ) ;
77
- let mut hostname = match self . override_server_name . as_deref ( ) {
78
- Some ( h) => h,
79
- None => dst. host ( ) . unwrap_or_default ( ) ,
80
- } ;
81
-
82
- // Remove square brackets around IPv6 address.
83
- if let Some ( trimmed) = hostname
84
- . strip_prefix ( '[' )
85
- . and_then ( |h| h. strip_suffix ( ']' ) )
86
- {
87
- hostname = trimmed;
88
- }
84
+ let cfg = self . tls_config . clone ( ) ;
85
+ let mut hostname = match self . override_server_name . as_deref ( ) {
86
+ Some ( h) => h,
87
+ None => dst. host ( ) . unwrap_or_default ( ) ,
88
+ } ;
89
89
90
- let hostname = match ServerName :: try_from ( hostname) {
91
- Ok ( dns_name) => dns_name. to_owned ( ) ,
92
- Err ( _) => {
93
- let err = io:: Error :: new ( io:: ErrorKind :: Other , "invalid dnsname" ) ;
94
- return Box :: pin ( async move { Err ( Box :: new ( err) . into ( ) ) } ) ;
95
- }
96
- } ;
97
- let connecting_future = self . http . call ( dst) ;
98
-
99
- let f = async move {
100
- let tcp = connecting_future
101
- . await
102
- . map_err ( Into :: into) ?;
103
- let connector = TlsConnector :: from ( cfg) ;
104
- let tls = connector
105
- . connect ( hostname, tcp)
106
- . await
107
- . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e) ) ?;
108
- Ok ( MaybeHttpsStream :: Https ( tls) )
109
- } ;
110
- Box :: pin ( f)
111
- } else {
112
- let err = io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "Unsupported scheme {scheme}" ) ) ;
113
- Box :: pin ( async move { Err ( err. into ( ) ) } )
90
+ // Remove square brackets around IPv6 address.
91
+ if let Some ( trimmed) = hostname
92
+ . strip_prefix ( '[' )
93
+ . and_then ( |h| h. strip_suffix ( ']' ) )
94
+ {
95
+ hostname = trimmed;
114
96
}
97
+
98
+ let hostname = match ServerName :: try_from ( hostname) {
99
+ Ok ( dns_name) => dns_name. to_owned ( ) ,
100
+ Err ( _) => {
101
+ let err = io:: Error :: new ( io:: ErrorKind :: Other , "invalid dnsname" ) ;
102
+ return Box :: pin ( async move { Err ( Box :: new ( err) . into ( ) ) } ) ;
103
+ }
104
+ } ;
105
+ let connecting_future = self . http . call ( dst) ;
106
+
107
+ let f = async move {
108
+ let tcp = connecting_future
109
+ . await
110
+ . map_err ( Into :: into) ?;
111
+ let connector = TlsConnector :: from ( cfg) ;
112
+ let tls = connector
113
+ . connect ( hostname, tcp)
114
+ . await
115
+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e) ) ?;
116
+ Ok ( MaybeHttpsStream :: Https ( tls) )
117
+ } ;
118
+ Box :: pin ( f)
115
119
}
116
120
}
117
121
0 commit comments