async_http_client_lite/
client_ext_ws.rs1use futures_io::{AsyncRead, AsyncWrite};
2
3#[cfg(feature = "ws__async_tungstenite")]
5use std::io;
6
7#[cfg(feature = "ws__async_tungstenite")]
8use http::Response;
9
10#[cfg(feature = "ws__async_tungstenite")]
12pub use async_tungstenite::tungstenite::protocol::WebSocketConfig as AsyncTungsteniteWebSocketConfig;
13#[cfg(feature = "ws__async_tungstenite")]
14use async_tungstenite::{
15 client_async_with_config as async_tungstenite_client_async_with_config,
16 tungstenite::{
17 client::IntoClientRequest as AsyncTungsteniteIntoClientRequest,
18 error::Error as AsyncTungsteniteWsError,
19 },
20 WebSocketStream as AsyncTungsteniteWebSocketStream,
21};
22
23use crate::client::Client;
25
26impl<S> Client<S>
30where
31 S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
32{
33 #[cfg(feature = "ws__async_tungstenite")]
34 pub async fn into_async_tungstenite<R>(
35 self,
36 request: R,
37 config: Option<AsyncTungsteniteWebSocketConfig>,
38 ) -> std::result::Result<
39 (AsyncTungsteniteWebSocketStream<S>, Response<()>),
40 AsyncTungsteniteWsError,
41 >
42 where
43 R: AsyncTungsteniteIntoClientRequest + Unpin,
44 {
45 let request = request.into_client_request()?;
46 match request.uri().scheme_str() {
47 Some("wss") | Some("https") => {
48 return Err(AsyncTungsteniteWsError::Io(io::Error::new(
49 io::ErrorKind::InvalidInput,
50 "Please refer to https://github.com/bk-rs/async-http-client-lite/blob/master/demos/async_net/src/wss.rs",
51 )))
52 }
53 _ => {}
54 }
55
56 let (stream, response) =
57 async_tungstenite_client_async_with_config(request, self.into_inner(), config).await?;
58
59 Ok((stream, response))
60 }
61}