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 //! - HTTP/1.1 20 //! - HTTP/2 21 // TODO: Need doc. 22 23 // ylong_http crate re-export. 24 #[cfg(any(feature = "ylong_base", feature = "tokio_base"))] 25 pub use ylong_http::body::{EmptyBody, ReusableReader, TextBody}; 26 pub use ylong_http::headers::{ 27 Header, HeaderName, HeaderValue, HeaderValueIter, HeaderValueIterMut, Headers, HeadersIntoIter, 28 HeadersIter, HeadersIterMut, 29 }; 30 pub use ylong_http::request::method::Method; 31 pub use ylong_http::request::uri::{Scheme, Uri}; 32 pub use ylong_http::request::{Request, RequestPart}; 33 pub use ylong_http::response::status::StatusCode; 34 pub use ylong_http::response::ResponsePart; 35 pub use ylong_http::version::Version; 36 37 #[macro_use] 38 #[cfg(all( 39 any(feature = "async", feature = "sync"), 40 any(feature = "http1_1", feature = "http2"), 41 ))] 42 mod error; 43 44 #[cfg(all(feature = "async", any(feature = "http1_1", feature = "http2")))] 45 pub mod async_impl; 46 47 #[cfg(all(feature = "sync", any(feature = "http1_1", feature = "http2")))] 48 pub mod sync_impl; 49 50 #[cfg(all( 51 any(feature = "async", feature = "sync"), 52 any(feature = "http1_1", feature = "http2"), 53 ))] 54 pub(crate) mod util; 55 56 #[cfg(all( 57 any(feature = "async", feature = "sync"), 58 any(feature = "http1_1", feature = "http2"), 59 ))] 60 pub use error::{ErrorKind, HttpClientError}; 61 #[cfg(all( 62 any(feature = "async", feature = "sync"), 63 any(feature = "http1_1", feature = "http2"), 64 ))] 65 pub use util::*; 66 67 // Runtime components import adapter. 68 #[cfg(any(feature = "tokio_base", feature = "ylong_base"))] 69 pub(crate) mod runtime { 70 #[cfg(all(feature = "tokio_base", any(feature = "http2", feature = "http3")))] 71 pub(crate) use tokio::{ 72 io::{split, ReadHalf, WriteHalf}, 73 spawn, 74 sync::{ 75 mpsc::{ 76 channel as bounded_channel, error::SendError, unbounded_channel, 77 Receiver as BoundedReceiver, Sender as BoundedSender, UnboundedReceiver, 78 UnboundedSender, 79 }, 80 Mutex as AsyncMutex, MutexGuard, 81 }, 82 }; 83 #[cfg(all(feature = "tokio_base", feature = "async"))] 84 pub(crate) use tokio::{ 85 io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}, 86 net::TcpStream, 87 task::{spawn_blocking, JoinHandle}, 88 time::{sleep, timeout, Sleep}, 89 }; 90 #[cfg(feature = "ylong_base")] 91 pub(crate) use ylong_runtime::{ 92 io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}, 93 net::TcpStream, 94 spawn_blocking, 95 task::JoinHandle, 96 time::{sleep, timeout, Sleep}, 97 }; 98 // TODO add ReadHalf and WriteHalf 99 #[cfg(all(feature = "ylong_base", any(feature = "http2", feature = "http3")))] 100 pub(crate) use ylong_runtime::{ 101 spawn, 102 sync::{ 103 error::SendError, 104 mpsc::{ 105 bounded_channel, unbounded_channel, BoundedReceiver, BoundedSender, 106 UnboundedReceiver, UnboundedSender, 107 }, 108 Mutex as AsyncMutex, MutexGuard, 109 }, 110 }; 111 112 #[cfg(all(feature = "ylong_base", feature = "http2"))] 113 pub(crate) use crate::{split, Reader as ReadHalf, Writer as WriteHalf}; 114 } 115