@@ -7,6 +7,7 @@ use std::convert::From;
77use std:: fmt;
88use hyper:: Error as HttpError ;
99use url:: ParseError ;
10+ use server:: upgrade:: HyperIntoWsError ;
1011
1112#[ cfg( any( feature="sync-ssl" , feature="async-ssl" ) ) ]
1213use native_tls:: Error as TlsError ;
@@ -16,6 +17,12 @@ use native_tls::HandshakeError as TlsHandshakeError;
1617/// The type used for WebSocket results
1718pub type WebSocketResult < T > = Result < T , WebSocketError > ;
1819
20+ pub mod async {
21+ use futures:: Future ;
22+ use super :: WebSocketError ;
23+ pub type WebSocketFuture < I > = Box < Future < Item = I , Error = WebSocketError > > ;
24+ }
25+
1926/// Represents a WebSocket error
2027#[ derive( Debug ) ]
2128pub enum WebSocketError {
@@ -154,6 +161,25 @@ impl From<WSUrlErrorKind> for WebSocketError {
154161 }
155162}
156163
164+ impl From < HyperIntoWsError > for WebSocketError {
165+ fn from ( err : HyperIntoWsError ) -> WebSocketError {
166+ use self :: HyperIntoWsError :: * ;
167+ use WebSocketError :: * ;
168+ match err {
169+ Io ( io) => IoError ( io) ,
170+ Parsing ( err) => HttpError ( err) ,
171+ MethodNotGet => ProtocolError ( "Request method must be GET" ) ,
172+ UnsupportedHttpVersion => ProtocolError ( "Unsupported request HTTP version" ) ,
173+ UnsupportedWebsocketVersion => ProtocolError ( "Unsupported WebSocket version" ) ,
174+ NoSecWsKeyHeader => ProtocolError ( "Missing Sec-WebSocket-Key header" ) ,
175+ NoWsUpgradeHeader => ProtocolError ( "Invalid Upgrade WebSocket header" ) ,
176+ NoUpgradeHeader => ProtocolError ( "Missing Upgrade WebSocket header" ) ,
177+ NoWsConnectionHeader => ProtocolError ( "Invalid Connection WebSocket header" ) ,
178+ NoConnectionHeader => ProtocolError ( "Missing Connection WebSocket header" ) ,
179+ }
180+ }
181+ }
182+
157183/// Represents a WebSocket URL error
158184#[ derive( Debug ) ]
159185pub enum WSUrlErrorKind {
0 commit comments