File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,34 @@ impl NetworkConnector for HttpConnector {
255
255
}
256
256
}
257
257
258
+ /// A closure as a connector used to generate TcpStreams per request
259
+ ///
260
+ /// # Example
261
+ ///
262
+ /// Basic example:
263
+ ///
264
+ /// ```norun
265
+ /// Client::with_connector(|addr: &str, port: u16, scheme: &str| {
266
+ /// TcpStream::connect(&(addr, port))
267
+ /// });
268
+ /// ```
269
+ ///
270
+ /// Example using TcpBuilder from the net2 crate if you want to configure your source socket:
271
+ ///
272
+ /// ```norun
273
+ /// Client::with_connector(|addr: &str, port: u16, scheme: &str| {
274
+ /// let b = try!(TcpBuilder::new_v4());
275
+ /// try!(b.bind("127.0.0.1:0"));
276
+ /// b.connect(&(addr, port))
277
+ /// });
278
+ /// ```
279
+ impl < F > NetworkConnector for F where F : Fn ( & str , u16 , & str ) -> io:: Result < TcpStream > {
280
+ type Stream = HttpStream ;
281
+
282
+ fn connect ( & self , host : & str , port : u16 , scheme : & str ) -> :: Result < HttpStream > {
283
+ Ok ( HttpStream ( try!( ( * self ) ( host, port, scheme) ) ) )
284
+ }
285
+ }
258
286
259
287
/// An abstraction to allow any SSL implementation to be used with HttpsStreams.
260
288
pub trait Ssl {
You can’t perform that action at this time.
0 commit comments