@@ -115,15 +115,31 @@ impl TlsConnector {
115115 where
116116 IO : AsyncRead + AsyncWrite + Unpin ,
117117 {
118- self . connect_with ( domain, stream, |_| ( ) )
118+ self . connect_impl ( domain, stream, None , |_| ( ) )
119119 }
120120
121+ #[ inline]
121122 pub fn connect_with < IO , F > ( & self , domain : ServerName < ' static > , stream : IO , f : F ) -> Connect < IO >
122123 where
123124 IO : AsyncRead + AsyncWrite + Unpin ,
124125 F : FnOnce ( & mut ClientConnection ) ,
125126 {
126- let mut session = match ClientConnection :: new ( self . inner . clone ( ) , domain) {
127+ self . connect_impl ( domain, stream, None , f)
128+ }
129+
130+ fn connect_impl < IO , F > (
131+ & self ,
132+ domain : ServerName < ' static > ,
133+ stream : IO ,
134+ alpn_protocols : Option < Vec < Vec < u8 > > > ,
135+ f : F ,
136+ ) -> Connect < IO >
137+ where
138+ IO : AsyncRead + AsyncWrite + Unpin ,
139+ F : FnOnce ( & mut ClientConnection ) ,
140+ {
141+ let alpn = alpn_protocols. unwrap_or_else ( || self . inner . alpn_protocols . clone ( ) ) ;
142+ let mut session = match ClientConnection :: new_with_alpn ( self . inner . clone ( ) , domain, alpn) {
127143 Ok ( session) => session,
128144 Err ( error) => {
129145 return Connect ( MidHandshake :: Error {
@@ -158,12 +174,45 @@ impl TlsConnector {
158174 } ) )
159175 }
160176
177+ pub fn with_alpn ( & self , alpn_protocols : Vec < Vec < u8 > > ) -> TlsConnectorWithAlpn < ' _ > {
178+ TlsConnectorWithAlpn {
179+ inner : self ,
180+ alpn_protocols,
181+ }
182+ }
183+
161184 /// Get a read-only reference to underlying config
162185 pub fn config ( & self ) -> & Arc < ClientConfig > {
163186 & self . inner
164187 }
165188}
166189
190+ pub struct TlsConnectorWithAlpn < ' c > {
191+ inner : & ' c TlsConnector ,
192+ alpn_protocols : Vec < Vec < u8 > > ,
193+ }
194+
195+ impl TlsConnectorWithAlpn < ' _ > {
196+ #[ inline]
197+ pub fn connect < IO > ( self , domain : ServerName < ' static > , stream : IO ) -> Connect < IO >
198+ where
199+ IO : AsyncRead + AsyncWrite + Unpin ,
200+ {
201+ self . inner
202+ . connect_impl ( domain, stream, Some ( self . alpn_protocols ) , |_| ( ) )
203+ }
204+
205+ #[ inline]
206+ pub fn connect_with < IO , F > ( self , domain : ServerName < ' static > , stream : IO , f : F ) -> Connect < IO >
207+ where
208+ IO : AsyncRead + AsyncWrite + Unpin ,
209+ F : FnOnce ( & mut ClientConnection ) ,
210+ {
211+ self . inner
212+ . connect_impl ( domain, stream, Some ( self . alpn_protocols ) , f)
213+ }
214+ }
215+
167216impl TlsAcceptor {
168217 #[ inline]
169218 pub fn accept < IO > ( & self , stream : IO ) -> Accept < IO >
0 commit comments