@@ -51,12 +51,15 @@ impl<'a, N: NetworkListener + 'a> Iterator for NetworkConnections<'a, N> {
5151pub trait NetworkStream : Read + Write + Any + Send + Typeable {
5252 /// Get the remote address of the underlying connection.
5353 fn peer_addr ( & mut self ) -> io:: Result < SocketAddr > ;
54+
5455 /// Set the maximum time to wait for a read to complete.
5556 #[ cfg( feature = "timeouts" ) ]
5657 fn set_read_timeout ( & self , dur : Option < Duration > ) -> io:: Result < ( ) > ;
58+
5759 /// Set the maximum time to wait for a write to complete.
5860 #[ cfg( feature = "timeouts" ) ]
5961 fn set_write_timeout ( & self , dur : Option < Duration > ) -> io:: Result < ( ) > ;
62+
6063 /// This will be called when Stream should no longer be kept alive.
6164 #[ inline]
6265 fn close ( & mut self , _how : Shutdown ) -> io:: Result < ( ) > {
@@ -66,9 +69,8 @@ pub trait NetworkStream: Read + Write + Any + Send + Typeable {
6669 // Unsure about name and implementation...
6770
6871 #[ doc( hidden) ]
69- fn set_previous_response_expected_no_content ( & mut self , _expected : bool ) {
70-
71- }
72+ fn set_previous_response_expected_no_content ( & mut self , _expected : bool ) { }
73+
7274 #[ doc( hidden) ]
7375 fn previous_response_expected_no_content ( & self ) -> bool {
7476 false
@@ -79,6 +81,7 @@ pub trait NetworkStream: Read + Write + Any + Send + Typeable {
7981pub trait NetworkConnector {
8082 /// Type of Stream to create
8183 type Stream : Into < Box < NetworkStream + Send > > ;
84+
8285 /// Connect to a remote address.
8386 fn connect ( & self , host : & str , port : u16 , scheme : & str ) -> :: Result < Self :: Stream > ;
8487}
@@ -215,13 +218,17 @@ impl Clone for HttpListener {
215218 }
216219}
217220
218- impl HttpListener {
221+ impl From < TcpListener > for HttpListener {
222+ fn from ( listener : TcpListener ) -> HttpListener {
223+ HttpListener ( listener)
224+ }
225+ }
219226
227+ impl HttpListener {
220228 /// Start listening to an address over HTTP.
221229 pub fn new < To : ToSocketAddrs > ( addr : To ) -> :: Result < HttpListener > {
222230 Ok ( HttpListener ( try!( TcpListener :: bind ( addr) ) ) )
223231 }
224-
225232}
226233
227234impl NetworkListener for HttpListener {
@@ -382,17 +389,17 @@ impl NetworkConnector for HttpConnector {
382389/// A closure as a connector used to generate TcpStreams per request
383390///
384391/// # Example
385- ///
392+ ///
386393/// Basic example:
387- ///
394+ ///
388395/// ```norun
389396/// Client::with_connector(|addr: &str, port: u16, scheme: &str| {
390397/// TcpStream::connect(&(addr, port))
391398/// });
392399/// ```
393- ///
400+ ///
394401/// Example using TcpBuilder from the net2 crate if you want to configure your source socket:
395- ///
402+ ///
396403/// ```norun
397404/// Client::with_connector(|addr: &str, port: u16, scheme: &str| {
398405/// let b = try!(TcpBuilder::new_v4());
@@ -499,7 +506,6 @@ pub struct HttpsListener<S: Ssl> {
499506}
500507
501508impl < S : Ssl > HttpsListener < S > {
502-
503509 /// Start listening to an address over HTTPS.
504510 pub fn new < To : ToSocketAddrs > ( addr : To , ssl : S ) -> :: Result < HttpsListener < S > > {
505511 HttpListener :: new ( addr) . map ( |l| HttpsListener {
@@ -508,6 +514,13 @@ impl<S: Ssl> HttpsListener<S> {
508514 } )
509515 }
510516
517+ /// Construct an HttpsListener from a bound `TcpListener`.
518+ pub fn with_listener ( listener : HttpListener , ssl : S ) -> HttpsListener < S > {
519+ HttpsListener {
520+ listener : listener,
521+ ssl : ssl
522+ }
523+ }
511524}
512525
513526impl < S : Ssl + Clone > NetworkListener for HttpsListener < S > {
@@ -576,7 +589,6 @@ mod openssl {
576589 use openssl:: x509:: X509FileType ;
577590 use super :: { NetworkStream , HttpStream } ;
578591
579-
580592 /// An implementation of `Ssl` for OpenSSL.
581593 ///
582594 /// # Example
@@ -678,7 +690,6 @@ mod tests {
678690
679691 let mock = stream. downcast :: < MockStream > ( ) . ok ( ) . unwrap ( ) ;
680692 assert_eq ! ( mock, Box :: new( MockStream :: new( ) ) ) ;
681-
682693 }
683694
684695 #[ test]
@@ -688,6 +699,6 @@ mod tests {
688699
689700 let mock = unsafe { stream. downcast_unchecked :: < MockStream > ( ) } ;
690701 assert_eq ! ( mock, Box :: new( MockStream :: new( ) ) ) ;
691-
692702 }
693703}
704+
0 commit comments