@@ -115,15 +115,31 @@ impl TlsConnector {
115
115
where
116
116
IO : AsyncRead + AsyncWrite + Unpin ,
117
117
{
118
- self . connect_with ( domain, stream, |_| ( ) )
118
+ self . connect_impl ( domain, stream, None , |_| ( ) )
119
119
}
120
120
121
+ #[ inline]
121
122
pub fn connect_with < IO , F > ( & self , domain : ServerName < ' static > , stream : IO , f : F ) -> Connect < IO >
122
123
where
123
124
IO : AsyncRead + AsyncWrite + Unpin ,
124
125
F : FnOnce ( & mut ClientConnection ) ,
125
126
{
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) {
127
143
Ok ( session) => session,
128
144
Err ( error) => {
129
145
return Connect ( MidHandshake :: Error {
@@ -158,12 +174,45 @@ impl TlsConnector {
158
174
} ) )
159
175
}
160
176
177
+ pub fn with_alpn ( & self , alpn_protocols : Vec < Vec < u8 > > ) -> TlsConnectorWithAlpn < ' _ > {
178
+ TlsConnectorWithAlpn {
179
+ inner : self ,
180
+ alpn_protocols,
181
+ }
182
+ }
183
+
161
184
/// Get a read-only reference to underlying config
162
185
pub fn config ( & self ) -> & Arc < ClientConfig > {
163
186
& self . inner
164
187
}
165
188
}
166
189
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
+
167
216
impl TlsAcceptor {
168
217
#[ inline]
169
218
pub fn accept < IO > ( & self , stream : IO ) -> Accept < IO >
0 commit comments