@@ -68,6 +68,7 @@ pub struct ServiceRequest<'r, 'c> {
6868 pub req : & ' r mut Request < BoxBody > ,
6969 pub client : & ' c Client ,
7070 pub timeout : Duration ,
71+ pub sni_hostname : Option < & ' r str > ,
7172}
7273
7374/// type alias for object safe wrapper of type implement [Service] trait.
@@ -85,7 +86,12 @@ pub(crate) fn base_service() -> HttpService {
8586 #[ cfg( any( feature = "http1" , feature = "http2" , feature = "http3" ) ) ]
8687 use crate :: { error:: TimeoutError , timeout:: Timeout } ;
8788
88- let ServiceRequest { req, client, timeout } = req;
89+ let ServiceRequest {
90+ req,
91+ client,
92+ timeout,
93+ sni_hostname,
94+ } = req;
8995
9096 let uri = Uri :: try_parse ( req. uri ( ) ) ?;
9197
@@ -94,13 +100,13 @@ pub(crate) fn base_service() -> HttpService {
94100 #[ allow( unused_mut) ]
95101 let mut version = req. version ( ) ;
96102
97- let mut connect = Connect :: new ( uri) ;
103+ let mut connect = Connect :: new ( uri, sni_hostname ) ;
98104
99105 let _date = client. date_service . handle ( ) ;
100106
101107 loop {
102108 match version {
103- Version :: HTTP_2 | Version :: HTTP_3 => match client. shared_pool . acquire ( & connect. uri ) . await {
109+ Version :: HTTP_2 | Version :: HTTP_3 => match client. shared_pool . acquire ( & connect) . await {
104110 shared:: AcquireOutput :: Conn ( mut _conn) => {
105111 let mut _timer = Box :: pin ( tokio:: time:: sleep ( timeout) ) ;
106112 * req. version_mut ( ) = version;
@@ -155,7 +161,7 @@ pub(crate) fn base_service() -> HttpService {
155161 if let Ok ( Ok ( conn) ) = crate :: h3:: proto:: connect (
156162 & client. h3_client ,
157163 connect. addrs ( ) ,
158- connect. hostname ( ) ,
164+ connect. sni_hostname ( ) ,
159165 )
160166 . timeout ( timer. as_mut ( ) )
161167 . await
@@ -197,7 +203,7 @@ pub(crate) fn base_service() -> HttpService {
197203
198204 #[ cfg( feature = "http1" ) ]
199205 {
200- client. exclusive_pool . try_add ( & connect. uri , conn) ;
206+ client. exclusive_pool . try_add ( & connect, conn) ;
201207 // downgrade request version to what alpn protocol suggested from make_exclusive.
202208 version = alpn_version;
203209 }
@@ -212,7 +218,7 @@ pub(crate) fn base_service() -> HttpService {
212218 _ => unreachable ! ( "outer match didn't handle version correctly." ) ,
213219 } ,
214220 } ,
215- version => match client. exclusive_pool . acquire ( & connect. uri ) . await {
221+ version => match client. exclusive_pool . acquire ( & connect) . await {
216222 exclusive:: AcquireOutput :: Conn ( mut _conn) => {
217223 * req. version_mut ( ) = version;
218224
@@ -307,6 +313,7 @@ mod test {
307313 req,
308314 client : & self . 0 ,
309315 timeout : self . 0 . timeout_config . request_timeout ,
316+ sni_hostname : None ,
310317 }
311318 }
312319 }
0 commit comments