cyfs_util/util/
async_h1.rs

1pub mod async_h1_helper {
2    use async_std::io::{Read, Write};
3    use http_types::{Request, Response};
4
5    /// Opens an HTTP/1.1 connection to a remote host with timeout.
6    pub async fn connect_timeout<RW>(stream: RW, req: Request, dur: std::time::Duration) -> http_types::Result<Response>
7    where
8        RW: Read + Write + Send + Sync + Unpin + 'static,
9    {
10        // CYFS LOG
11        match async_std::future::timeout(dur, async_h1::connect(stream, req)).await {
12            Ok(ret) => {
13                ret
14            }
15            Err(async_std::future::TimeoutError { .. }) => {
16                let msg = format!("http request timeout! dur={:?}", dur);
17                log::error!("{}", msg);
18                Err(http_types::Error::from_str(http_types::StatusCode::GatewayTimeout, msg))
19            }
20        }
21    }
22}