@@ -60,61 +60,64 @@ 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
- if let Some ( sch) = dst. scheme ( ) {
64
- if sch == & http:: uri:: Scheme :: HTTP && !self . force_https {
65
- let connecting_future = self . http . call ( dst) ;
66
-
67
- let f = async move {
68
- let tcp = connecting_future
69
- . await
70
- . map_err ( Into :: into) ?;
71
-
72
- Ok ( MaybeHttpsStream :: Http ( tcp) )
73
- } ;
74
- Box :: pin ( f)
75
- } else if sch == & 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
- }
89
-
90
- let hostname = match ServerName :: try_from ( hostname) {
91
- Ok ( dnsname) => dnsname. 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 =
113
- io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "Unsupported scheme {}" , sch) ) ;
114
- Box :: pin ( async move { Err ( err. into ( ) ) } )
63
+ let scheme = match dst. scheme ( ) {
64
+ Some ( scheme) => scheme,
65
+ None => {
66
+ return Box :: pin ( async move {
67
+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , "missing scheme" ) . into ( ) )
68
+ } )
69
+ }
70
+ } ;
71
+
72
+ if scheme == & http:: uri:: Scheme :: HTTP && !self . force_https {
73
+ let connecting_future = self . http . call ( dst) ;
74
+
75
+ let f = async move {
76
+ let tcp = connecting_future
77
+ . await
78
+ . map_err ( Into :: into) ?;
79
+
80
+ Ok ( MaybeHttpsStream :: Http ( tcp) )
81
+ } ;
82
+ Box :: pin ( f)
83
+ } else if scheme == & http:: uri:: Scheme :: HTTPS {
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
+
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;
115
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)
116
119
} else {
117
- let err = io:: Error :: new ( io:: ErrorKind :: Other , "Missing scheme" ) ;
120
+ let err = io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "Unsupported scheme {scheme}" ) ) ;
118
121
Box :: pin ( async move { Err ( err. into ( ) ) } )
119
122
}
120
123
}
0 commit comments