1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 //! `ylong_http_client` provides a HTTP client that based on `ylong_http` crate. 15 //! You can use the client to send request to a server, and then get the 16 //! response. 17 //! 18 //! # Supported HTTP Version 19 //! - HTTP1.1 20 // TODO: Need doc. 21 22 // ylong_http crate re-export. 23 pub use ylong_http::body::{EmptyBody, TextBody}; 24 pub use ylong_http::request::method::Method; 25 pub use ylong_http::request::uri::{Scheme, Uri}; 26 pub use ylong_http::request::{Request, RequestPart}; 27 pub use ylong_http::response::status::StatusCode; 28 pub use ylong_http::response::ResponsePart; 29 pub use ylong_http::version::Version; 30 31 #[cfg(all(feature = "async", any(feature = "http1_1", feature = "http2")))] 32 pub mod async_impl; 33 34 #[cfg(all(feature = "async", any(feature = "http1_1", feature = "http2")))] 35 pub use async_impl::{Body, RequestBuilder, Response}; 36 37 #[cfg(all(feature = "sync", any(feature = "http1_1", feature = "http2")))] 38 pub mod sync_impl; 39 40 #[cfg(all( 41 any(feature = "async", feature = "sync"), 42 any(feature = "http1_1", feature = "http2"), 43 ))] 44 mod error; 45 46 #[cfg(all( 47 any(feature = "async", feature = "sync"), 48 any(feature = "http1_1", feature = "http2"), 49 ))] 50 pub use error::{ErrorKind, HttpClientError}; 51 52 #[cfg(all( 53 any(feature = "async", feature = "sync"), 54 any(feature = "http1_1", feature = "http2"), 55 ))] 56 pub mod util; 57 58 #[cfg(all(feature = "tokio_base", feature = "http2"))] 59 pub(crate) use tokio::sync::{ 60 mpsc::{error::TryRecvError, unbounded_channel, UnboundedReceiver, UnboundedSender}, 61 Mutex as AsyncMutex, MutexGuard, 62 }; 63 #[cfg(all(feature = "tokio_base", feature = "async"))] 64 pub(crate) use tokio::{ 65 io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}, 66 net::TcpStream, 67 time::{sleep, timeout, Sleep}, 68 }; 69 #[cfg(all( 70 any(feature = "async", feature = "sync"), 71 any(feature = "http1_1", feature = "http2"), 72 ))] 73 pub use util::*; 74 #[cfg(all(feature = "ylong_base", feature = "http2"))] 75 pub(crate) use ylong_runtime::sync::{ 76 mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}, 77 Mutex as AsyncMutex, MutexGuard, RecvError as TryRecvError, 78 }; 79 #[cfg(all(feature = "ylong_base", feature = "async"))] 80 pub(crate) use ylong_runtime::{ 81 io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}, 82 net::TcpStream, 83 time::{sleep, timeout, Sleep}, 84 }; 85