11//! Async WebSocket support for compio.
22//!
3- //! This library is an implementation of WebSocket handshakes and streams for compio.
4- //! It is based on the tungstenite crate which implements all required WebSocket protocol
5- //! logic. This crate brings compio support / compio integration to it.
3+ //! This library is an implementation of WebSocket handshakes and streams for
4+ //! compio. It is based on the tungstenite crate which implements all required
5+ //! WebSocket protocol logic. This crate brings compio support / compio
6+ //! integration to it.
67//!
78//! Each WebSocket stream implements message reading and writing.
89
@@ -16,21 +17,16 @@ use std::io::ErrorKind;
1617
1718use compio_io:: { AsyncRead , AsyncWrite } ;
1819use growable_sync_stream:: GrowableSyncStream ;
19-
2020use tungstenite:: {
2121 Error as WsError , HandshakeError , Message , WebSocket ,
2222 client:: IntoClientRequest ,
2323 handshake:: server:: { Callback , NoCallback } ,
2424 protocol:: CloseFrame ,
2525} ;
26-
27- pub use crate :: stream:: MaybeTlsStream ;
28-
29- pub use tungstenite:: { Message as WebSocketMessage , handshake:: client:: Response } ;
30-
31- pub use tungstenite:: protocol:: WebSocketConfig ;
32-
33- pub use tungstenite:: error:: Error as TungsteniteError ;
26+ pub use tungstenite:: {
27+ Message as WebSocketMessage , error:: Error as TungsteniteError , handshake:: client:: Response ,
28+ protocol:: WebSocketConfig ,
29+ } ;
3430
3531#[ cfg( feature = "rustls" ) ]
3632pub use crate :: rustls:: {
@@ -39,6 +35,7 @@ pub use crate::rustls::{
3935 connect_async_with_config, connect_async_with_tls_connector,
4036 connect_async_with_tls_connector_and_config,
4137} ;
38+ pub use crate :: stream:: MaybeTlsStream ;
4239
4340pub struct WebSocketStream < S > {
4441 inner : WebSocket < GrowableSyncStream < S > > ,
@@ -140,8 +137,8 @@ where
140137 accept_hdr_async ( stream, NoCallback ) . await
141138}
142139
143- /// The same as `accept_async()` but the one can specify a websocket configuration.
144- /// Please refer to `accept_async()` for more details.
140+ /// The same as `accept_async()` but the one can specify a websocket
141+ /// configuration. Please refer to `accept_async()` for more details.
145142pub async fn accept_async_with_config < S > (
146143 stream : S ,
147144 config : Option < WebSocketConfig > ,
@@ -153,9 +150,9 @@ where
153150}
154151/// Accepts a new WebSocket connection with the provided stream.
155152///
156- /// This function does the same as `accept_async()` but accepts an extra callback
157- /// for header processing. The callback receives headers of the incoming
158- /// requests and is able to add extra headers to the reply.
153+ /// This function does the same as `accept_async()` but accepts an extra
154+ /// callback for header processing. The callback receives headers of the
155+ /// incoming requests and is able to add extra headers to the reply.
159156pub async fn accept_hdr_async < S , C > ( stream : S , callback : C ) -> Result < WebSocketStream < S > , WsError >
160157where
161158 S : AsyncRead + AsyncWrite + Unpin + std:: fmt:: Debug ,
@@ -164,8 +161,8 @@ where
164161 accept_hdr_with_config_async ( stream, callback, None ) . await
165162}
166163
167- /// The same as `accept_hdr_async()` but the one can specify a websocket configuration.
168- /// Please refer to `accept_hdr_async()` for more details.
164+ /// The same as `accept_hdr_async()` but the one can specify a websocket
165+ /// configuration. Please refer to `accept_hdr_async()` for more details.
169166pub async fn accept_hdr_with_config_async < S , C > (
170167 stream : S ,
171168 callback : C ,
@@ -228,8 +225,8 @@ where
228225 client_async_with_config ( request, stream, None ) . await
229226}
230227
231- /// The same as `client_async()` but the one can specify a websocket configuration.
232- /// Please refer to `client_async()` for more details.
228+ /// The same as `client_async()` but the one can specify a websocket
229+ /// configuration. Please refer to `client_async()` for more details.
233230pub async fn client_async_with_config < R , S > (
234231 request : R ,
235232 stream : S ,
@@ -281,11 +278,12 @@ pub(crate) fn domain(
281278 . uri ( )
282279 . host ( )
283280 . map ( |host| {
284- // If host is an IPv6 address, it might be surrounded by brackets. These brackets are
285- // *not* part of a valid IP, so they must be stripped out.
281+ // If host is an IPv6 address, it might be surrounded by brackets. These
282+ // brackets are *not* part of a valid IP, so they must be stripped
283+ // out.
286284 //
287- // The URI from the request is guaranteed to be valid, so we don't need a separate
288- // check for the closing bracket.
285+ // The URI from the request is guaranteed to be valid, so we don't need a
286+ // separate check for the closing bracket.
289287 let host = if host. starts_with ( '[' ) {
290288 & host[ 1 ..host. len ( ) - 1 ]
291289 } else {
0 commit comments