11//! Everything you need to create a client connection to a websocket.
22
33use std:: borrow:: Cow ;
4- use std:: net:: TcpStream ;
5- use std:: net:: ToSocketAddrs ;
64pub use url:: { Url , ParseError } ;
7- use url:: Position ;
8- use hyper:: version:: HttpVersion ;
9- use hyper:: http:: h1:: Incoming ;
10- use hyper:: http:: RawStatus ;
11- use hyper:: status:: StatusCode ;
12- use hyper:: buffer:: BufReader ;
13- use hyper:: method:: Method ;
14- use hyper:: uri:: RequestUri ;
15- use hyper:: http:: h1:: parse_response;
16- use hyper:: header:: { Headers , Header , HeaderFormat , Host , Connection , ConnectionOption , Upgrade ,
17- Protocol , ProtocolName } ;
18- use unicase:: UniCase ;
195use header:: extensions:: Extension ;
20- use header:: { WebSocketAccept , WebSocketKey , WebSocketVersion , WebSocketProtocol ,
21- WebSocketExtensions , Origin } ;
22- use result:: { WSUrlErrorKind , WebSocketResult , WebSocketError } ;
23- use stream:: { self , Stream } ;
6+ use header:: { WebSocketKey , WebSocketVersion , WebSocketProtocol , WebSocketExtensions , Origin } ;
7+ use hyper:: header:: { Headers , Header , HeaderFormat } ;
8+ use hyper:: version:: HttpVersion ;
9+
10+ #[ cfg( any( feature="sync" , feature="async" ) ) ]
11+ mod common_imports {
12+ pub use std:: net:: TcpStream ;
13+ pub use std:: net:: ToSocketAddrs ;
14+ pub use url:: Position ;
15+ pub use hyper:: http:: h1:: Incoming ;
16+ pub use hyper:: http:: RawStatus ;
17+ pub use hyper:: status:: StatusCode ;
18+ pub use hyper:: buffer:: BufReader ;
19+ pub use hyper:: method:: Method ;
20+ pub use hyper:: uri:: RequestUri ;
21+ pub use hyper:: http:: h1:: parse_response;
22+ pub use hyper:: header:: { Host , Connection , ConnectionOption , Upgrade , Protocol , ProtocolName } ;
23+ pub use unicase:: UniCase ;
24+ pub use header:: WebSocketAccept ;
25+ pub use result:: { WSUrlErrorKind , WebSocketResult , WebSocketError } ;
26+ pub use stream:: { self , Stream } ;
27+ }
28+ #[ cfg( any( feature="sync" , feature="async" ) ) ]
29+ use self :: common_imports:: * ;
2430
2531#[ cfg( feature="sync" ) ]
2632use super :: sync:: Client ;
@@ -29,7 +35,9 @@ use super::sync::Client;
2935use stream:: sync:: NetworkStream ;
3036
3137#[ cfg( any( feature="sync-ssl" , feature="async-ssl" ) ) ]
32- use native_tls:: { TlsStream , TlsConnector } ;
38+ use native_tls:: TlsConnector ;
39+ #[ cfg( feature="sync-ssl" ) ]
40+ use native_tls:: TlsStream ;
3341
3442#[ cfg( feature="async" ) ]
3543mod async_imports {
@@ -819,6 +827,7 @@ impl<'u> ClientBuilder<'u> {
819827 Ok ( async :: TcpStream :: connect ( & address, handle) )
820828 }
821829
830+ #[ cfg( any( feature="sync" , feature="async" ) ) ]
822831 fn build_request ( & mut self ) -> String {
823832 // enter host if available (unix sockets don't have hosts)
824833 if let Some ( host) = self . url . host_str ( ) {
@@ -855,6 +864,7 @@ impl<'u> ClientBuilder<'u> {
855864 resource
856865 }
857866
867+ #[ cfg( any( feature="sync" , feature="async" ) ) ]
858868 fn validate ( & self , response : & Incoming < RawStatus > ) -> WebSocketResult < ( ) > {
859869 let status = StatusCode :: from_u16 ( response. subject . 0 ) ;
860870
@@ -890,6 +900,7 @@ impl<'u> ClientBuilder<'u> {
890900 Ok ( ( ) )
891901 }
892902
903+ #[ cfg( any( feature="sync" , feature="async" ) ) ]
893904 fn extract_host_port ( & self , secure : Option < bool > ) -> WebSocketResult < ( & str , u16 ) > {
894905 let port = match ( self . url . port ( ) , secure) {
895906 ( Some ( port) , _) => port,
@@ -906,6 +917,7 @@ impl<'u> ClientBuilder<'u> {
906917 Ok ( ( host, port) )
907918 }
908919
920+ #[ cfg( feature="sync" ) ]
909921 fn establish_tcp ( & mut self , secure : Option < bool > ) -> WebSocketResult < TcpStream > {
910922 Ok ( TcpStream :: connect ( self . extract_host_port ( secure) ?) ?)
911923 }
0 commit comments