File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 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 {
255255 }
256256}
257257
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+ }
258286
259287/// An abstraction to allow any SSL implementation to be used with HttpsStreams.
260288pub trait Ssl {
You can’t perform that action at this time.
0 commit comments