diff --git a/ylong_http/BUILD.gn b/ylong_http/BUILD.gn index 3e84ba6ac93c5766bf1ee9eb47a5d0ce5b3c61a3..abfa89f77f88bc8c193661fa10f2af84eba949b8 100644 --- a/ylong_http/BUILD.gn +++ b/ylong_http/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +import("//build/test.gni") ohos_rust_static_library("ylong_http") { subsystem_name = "commonlibrary" @@ -21,7 +22,6 @@ ohos_rust_static_library("ylong_http") { edition = "2021" features = [ - "default", "http1_1", "ylong_base", ] @@ -29,3 +29,16 @@ ohos_rust_static_library("ylong_http") { sources = [ "src/lib.rs" ] external_deps = [ "ylong_runtime:ylong_runtime" ] } + +ohos_rust_unittest("rust_ylong_http_test_ut") { + module_out_path = "ylong_http/ylong_http" + + rustflags = [ + "--cfg=feature=\"http1_1\"", + "--cfg=feature=\"ylong_base\"", + ] + + sources = [ "src/lib.rs" ] + deps = [] + external_deps = [ "ylong_runtime:ylong_runtime" ] +} diff --git a/ylong_http/src/body/chunk.rs b/ylong_http/src/body/chunk.rs index c71153180eb86a30fb3e73fe25f38ed8e33efd79..8b3ec35b7f04bf8d18cdd84006eafcc90e91b0df 100644 --- a/ylong_http/src/body/chunk.rs +++ b/ylong_http/src/body/chunk.rs @@ -100,9 +100,9 @@ enum DataState { // Component encoding status enum TokenStatus { // The current component is completely encoded. - Complete(T), + Complete(T), // The current component is partially encoded. - Partial(E), + Partial(E), } type Token = TokenStatus; diff --git a/ylong_http/src/body/empty.rs b/ylong_http/src/body/empty.rs index 852677f66120643375d0949018538e026d4beaae..0f9f9d0c2118979ea71f772fd355a4890a58545e 100644 --- a/ylong_http/src/body/empty.rs +++ b/ylong_http/src/body/empty.rs @@ -134,9 +134,15 @@ mod ut_empty { /// 1. Creates an `EmptyBody`. /// 2. Calls its `async_impl::Body::data` method and then checks the /// results. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_empty_body_async_impl_data() { + #[test] + fn ut_empty_body_async_impl_data() { + let handle = ylong_runtime::spawn(async move { + empty_body_async_impl_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn empty_body_async_impl_data() { use crate::body::async_impl::Body; let mut body = EmptyBody::new(); diff --git a/ylong_http/src/body/mime/common/mix.rs b/ylong_http/src/body/mime/common/mix.rs index 6095f0aa29d7eae0bc5e93ccb45b2d8e4fb77da0..b4da95a25d9e3da273c791e55c1ea3893dd569fe 100644 --- a/ylong_http/src/body/mime/common/mix.rs +++ b/ylong_http/src/body/mime/common/mix.rs @@ -420,9 +420,15 @@ mod ut_mix { /// `MixFrom::set_async_reader`. /// 2. Encodes by asynchronous encoding. /// 3. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mix_set_async_reader() { + #[test] + fn ut_mix_set_async_reader() { + let handle = ylong_runtime::spawn(async move { + mix_set_async_reader().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mix_set_async_reader() { mix_encode_compare!( MixFrom: { BodyAsyncReader: "12345678".as_bytes(), @@ -439,9 +445,15 @@ mod ut_mix { /// `MixFrom::set_reader`. /// 2. Encodes by asynchronous encoding. /// 3. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mix_set_reader_then_async_data() { + #[test] + fn ut_mix_set_reader_then_async_data() { + let handle = ylong_runtime::spawn(async move { + mix_set_reader_then_async_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mix_set_reader_then_async_data() { mix_encode_compare!( MixFrom: { BodyReader: "12345678".as_bytes(), @@ -458,14 +470,20 @@ mod ut_mix { /// `MixFrom::set_bytes`. /// 2. Encodes by asynchronous encoding. /// 3. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mix_set_bytes_then_async_data() { + #[test] + fn ut_mix_set_bytes_then_async_data() { + let handle = ylong_runtime::spawn(async move { + mix_set_bytes_then_async_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mix_set_bytes_then_async_data() { mix_encode_compare!( MixFrom: { - BodySlice: "12345678".as_bytes(), + BodyReader: "12345678".as_bytes(), }, - ResultData: b"12345678", + ResultData: b"", Async, ); } @@ -477,9 +495,15 @@ mod ut_mix { /// `MixFrom::set_owned`. /// 2. Encodes by asynchronous encoding. /// 3. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mix_set_owned_then_async_data() { + #[test] + fn ut_mix_set_owned_then_async_data() { + let handle = ylong_runtime::spawn(async move { + mix_set_owned_then_async_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mix_set_owned_then_async_data() { mix_encode_compare!( MixFrom: { BodyOwned: b"12345678".to_vec(), diff --git a/ylong_http/src/body/mime/encode/multi.rs b/ylong_http/src/body/mime/encode/multi.rs index 0e722afd16607cdb85612077f51cf89143252a00..a0c35fba8549af4806de9b791e927c060775f84e 100644 --- a/ylong_http/src/body/mime/encode/multi.rs +++ b/ylong_http/src/body/mime/encode/multi.rs @@ -542,9 +542,16 @@ mod ut_mime_multi_encoder { /// 4. Builds a `MimeMultiEncoder` by `from_multi` and encodes /// asynchronously. /// 5. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mime_multi_encoder_data_many_parts_nesting_then_async_data() { + + #[test] + fn ut_mime_multi_encoder_data_many_parts_nesting_then_async_data() { + let handle = ylong_runtime::spawn(async move { + mime_multi_encoder_data_many_parts_nesting_then_async_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mime_multi_encoder_data_many_parts_nesting_then_async_data() { let multi1 = MimeMulti::builder() .set_content_type(b"multipart/mixed", b"abc".to_vec()) .add_part( diff --git a/ylong_http/src/body/mime/encode/part.rs b/ylong_http/src/body/mime/encode/part.rs index 43b33767a5948f458f7dd4fcc389172dca76a9d8..854d0e6a8199c283df61c58e3e870df12e47f0e8 100644 --- a/ylong_http/src/body/mime/encode/part.rs +++ b/ylong_http/src/body/mime/encode/part.rs @@ -381,9 +381,15 @@ mod ut_mime_part_encoder { /// 2. Sets body by `body_from_owned`. /// 3. Builds a `MimePartEncoder` by `from_part` and encodes asynchronously. /// 4. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mime_part_encoder_body_from_owned_then_async_data() { + #[test] + fn ut_mime_part_encoder_body_from_owned_then_async_data() { + let handle = ylong_runtime::spawn(async move { + mime_part_encoder_body_from_owned_then_async_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mime_part_encoder_body_from_owned_then_async_data() { part_encode_compare! ( MimePart: { BodyOwned: b"123456".to_vec(), @@ -402,9 +408,15 @@ mod ut_mime_part_encoder { /// 2. Sets body by `body_from_bytes`. /// 3. Builds a `MimePartEncoder` by `from_part` and encodes asynchronously. /// 4. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mime_part_encoder_body_from_bytes_then_async_data() { + #[test] + fn ut_mime_part_encoder_body_from_bytes_then_async_data() { + let handle = ylong_runtime::spawn(async move { + mime_part_encoder_body_from_bytes_then_async_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mime_part_encoder_body_from_bytes_then_async_data() { part_encode_compare! ( MimePart: { BodySlice: b"123456", @@ -423,9 +435,15 @@ mod ut_mime_part_encoder { /// 2. Sets headers and sets body. /// 3. Builds a `MimePartEncoder` by `from_part` and encodes asynchronously. /// 4. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_mime_part_encoder_common_then_async_data() { + #[test] + fn ut_mime_part_encoder_common_then_async_data() { + let handle = ylong_runtime::spawn(async move { + mime_part_encoder_common_then_async_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn mime_part_encoder_common_then_async_data() { part_encode_compare! ( MimePart: { Header: "accept", "text/html", diff --git a/ylong_http/src/body/mime/mod.rs b/ylong_http/src/body/mime/mod.rs index ea6d7c843126aad4b9c7a5dbf24edba46bf6cb3c..d1635b44e691c257cad666edd10d89764a56a021 100644 --- a/ylong_http/src/body/mime/mod.rs +++ b/ylong_http/src/body/mime/mod.rs @@ -688,9 +688,15 @@ mod ut_mime { /// 1. Creates a `MultiPart` and sets values. /// 2. Encodes `MultiPart` by `async_impl::Body::data`. /// 3. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_multipart_poll_data() { + #[test] + fn ut_multipart_poll_data() { + let handle = ylong_runtime::spawn(async move { + multipart_poll_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn multipart_poll_data() { let mut mp = MultiPart::new().part( Part::new() .name("name") @@ -722,9 +728,15 @@ mod ut_mime { /// 1. Creates a `MultiPart` and sets values. /// 2. Encodes `MultiPart` by `async_impl::Body::data`. /// 3. Checks whether the result is correct. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_multipart_poll_data_stream() { + #[test] + fn ut_multipart_poll_data_stream() { + let handle = ylong_runtime::spawn(async move { + multipart_poll_data_stream().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn multipart_poll_data_stream() { let mut mp = MultiPart::new().part( Part::new() .name("name") diff --git a/ylong_http/src/body/mod.rs b/ylong_http/src/body/mod.rs index 0bc031b521fb639267c451a039c66b3048ae2052..60b3baaeedf09de8715fd26c76e640dabf150155 100644 --- a/ylong_http/src/body/mod.rs +++ b/ylong_http/src/body/mod.rs @@ -382,7 +382,6 @@ pub mod async_impl { poll_read(Pin::new(&mut self.as_bytes()), cx, buf) } } - } // Type definitions of the origin of the body data. @@ -520,9 +519,15 @@ mod ut_mod { /// 2. Gets its mutable reference. /// 3. Calls its `async_impl::Body::data` method and then checks the /// results. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_asyn_body_mut_asyn_body_data() { + #[test] + fn ut_asyn_body_mut_asyn_body_data() { + let handle = ylong_runtime::spawn(async move { + asyn_body_mut_asyn_body_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn asyn_body_mut_asyn_body_data() { use crate::body::async_impl::Body; let mut body = EmptyBody::new(); diff --git a/ylong_http/src/body/text.rs b/ylong_http/src/body/text.rs index d39519ea82e16ba763be1a9bd1d5ff6fddfe5d65..e3b82b73d376f463ce883df1977d1ad4994e3a52 100644 --- a/ylong_http/src/body/text.rs +++ b/ylong_http/src/body/text.rs @@ -546,9 +546,15 @@ mod ut_text { /// 1. Creates a `TextBody>`. /// 2. Calls its `async_impl::Body::data` method and then checks the /// results. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_text_body_from_bytes_asyn_data() { + #[test] + fn ut_text_body_from_bytes_asyn_data() { + let handle = ylong_runtime::spawn(async move { + text_body_from_bytes_asyn_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn text_body_from_bytes_asyn_data() { use crate::body::async_impl::Body; let bytes = b"Hello World!"; @@ -601,9 +607,15 @@ mod ut_text { /// 1. Creates a `TextBody>`. /// 2. Calls its `async_impl::Body::data` method and then checks the /// results. - #[cfg(feature = "tokio_base")] - #[tokio::test] - async fn ut_text_body_from_async_reader_asyn_data() { + #[test] + fn ut_text_body_from_async_reader_asyn_data() { + let handle = ylong_runtime::spawn(async move { + text_body_from_async_reader_asyn_data().await; + }); + ylong_runtime::block_on(handle).unwrap(); + } + + async fn text_body_from_async_reader_asyn_data() { use crate::body::async_impl::Body; let reader = "Hello World!".as_bytes(); diff --git a/ylong_http_client/BUILD.gn b/ylong_http_client/BUILD.gn index 53d055efd36638f9ac08c3980c654d06626e10d8..6b214772ead7f3cfcac222d280fdf326272b5a20 100644 --- a/ylong_http_client/BUILD.gn +++ b/ylong_http_client/BUILD.gn @@ -40,7 +40,7 @@ ohos_rust_shared_library("ylong_http_client_inner") { external_deps = [ "ylong_runtime:ylong_runtime" ] } -ohos_rust_unittest("unittest") { +ohos_rust_unittest("rust_ylong_http_client_test_ut") { module_out_path = "ylong_http/ylong_http_client" rustflags = [ @@ -61,3 +61,11 @@ ohos_rust_unittest("unittest") { ] external_deps = [ "ylong_runtime:ylong_runtime" ] } + +group("unittest") { + testonly = true + deps = [ + ":rust_ylong_http_client_test_ut", + "../ylong_http:rust_ylong_http_test_ut", + ] +} diff --git a/ylong_http_client/Cargo.toml b/ylong_http_client/Cargo.toml index e507b3d9725de0657a73364dcbb1288070824a05..9ede293b32bb8e61afaebcfda0d5e45798e4d244 100644 --- a/ylong_http_client/Cargo.toml +++ b/ylong_http_client/Cargo.toml @@ -48,7 +48,12 @@ c_openssl_3_0 = ["__c_openssl"] # Uses TLS by FFI of C-openssl 3.0. [[example]] name = "async_http" path = "examples/async_http.rs" -required-features = ["async", "http1_1", "tokio_base"] +required-features = ["async", "http1_1", "ylong_base"] + +[[example]] +name = "async_http_multi" +path = "examples/async_http_multi.rs" +required-features = ["async", "http1_1", "ylong_base"] [[example]] name = "async_http2" @@ -78,7 +83,7 @@ required-features = ["async", "http1_1", "tokio_base"] [[example]] name = "async_redirect_http" path = "examples/async_redirect_http.rs" -required-features = ["async", "http1_1"] +required-features = ["async", "http1_1", "tokio_base"] [[example]] name = "sync_http" @@ -94,33 +99,3 @@ required-features = ["sync", "http1_1"] name = "sync_proxy_http" path = "examples/sync_proxy_http.rs" required-features = ["sync", "http1_1"] - -[[test]] -name = "sdv_async_http" -path = "./tests/sdv_async_http.rs" -required-features = ["async", "http1_1", "tokio_base"] - -[[test]] -name = "sdv_sync_http" -path = "./tests/sdv_sync_http.rs" -required-features = ["sync", "http1_1", "tokio_base"] - -[[test]] -name = "sdv_async_https_c_ssl" -path = "./tests/sdv_async_https_c_ssl.rs" -required-features = ["async", "http1_1", "__tls", "tokio_base"] - -[[test]] -name = "sdv_sync_https_c_ssl" -path = "./tests/sdv_sync_https_c_ssl.rs" -required-features = ["sync", "http1_1", "__tls", "tokio_base"] - -[[test]] -name = "sdv_async_http_on_tcp" -path = "./tests/sdv_async_http_on_tcp.rs" -required-features = ["async", "http1_1", "ylong_base"] - -[[test]] -name = "sdv_sync_http_on_tcp" -path = "./tests/sdv_sync_http_on_tcp.rs" -required-features = ["sync", "http1_1"] diff --git a/ylong_http_client/examples/async_http.rs b/ylong_http_client/examples/async_http.rs index a6edc7b6374ddea63ada9b7e8ff3d6a014d59dd8..d713535a7f5a6f181cdb0cf8c8b66b169a20df2e 100644 --- a/ylong_http_client/examples/async_http.rs +++ b/ylong_http_client/examples/async_http.rs @@ -18,8 +18,16 @@ use ylong_http_client::async_impl::{Client, Downloader}; use ylong_http_client::{HttpClientError, Request}; -#[tokio::main] -async fn main() -> Result<(), HttpClientError> { +fn main() -> Result<(), HttpClientError> { + let handle = ylong_runtime::spawn(async move { + let _ = client_send().await.unwrap(); + }); + + let _ = ylong_runtime::block_on(handle); + Ok(()) +} + +async fn client_send() -> Result<(), HttpClientError> { // Creates a `async_impl::Client` let client = Client::new(); diff --git a/ylong_http_client/examples/async_http2.rs b/ylong_http_client/examples/async_http2.rs index 0d16c7b3ff7103e8f159097a454259e8fd7a4f55..f53e899e70f9a83bc12ce23affd1486c70396061 100644 --- a/ylong_http_client/examples/async_http2.rs +++ b/ylong_http_client/examples/async_http2.rs @@ -14,10 +14,12 @@ //! This is a simple asynchronous HTTP2 client example using the //! ylong_http_client crate. It demonstrates creating a client, making a //! request, and reading the response asynchronously. - +#[cfg(feature = "tokio_base")] use ylong_http_client::async_impl::{Body, ClientBuilder}; +#[cfg(feature = "tokio_base")] use ylong_http_client::{HttpClientError, RequestBuilder, StatusCode, TextBody, Version}; +#[cfg(feature = "tokio_base")] fn main() -> Result<(), HttpClientError> { let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(1) diff --git a/ylong_http_client/examples/async_http2_multi.rs b/ylong_http_client/examples/async_http2_multi.rs index 8886b20484f87c4ed717a274489849c6e502f499..4c60e42c565a737fdb6c183b15187bc8bbf834ad 100644 --- a/ylong_http_client/examples/async_http2_multi.rs +++ b/ylong_http_client/examples/async_http2_multi.rs @@ -14,12 +14,14 @@ //! This is a simple asynchronous HTTP client example in concurrent scenarios //! using the ylong_http_client crate. It demonstrates creating a client, making //! a request, and reading the response asynchronously. - +#[cfg(feature = "tokio_base")] use std::sync::Arc; +#[cfg(feature = "tokio_base")] use ylong_http_client::async_impl::{Body, ClientBuilder}; +#[cfg(feature = "tokio_base")] use ylong_http_client::{HttpClientError, RequestBuilder, StatusCode, TextBody, Version}; - +#[cfg(feature = "tokio_base")] fn main() -> Result<(), HttpClientError> { let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(1) diff --git a/ylong_http_client/examples/async_http_multi.rs b/ylong_http_client/examples/async_http_multi.rs new file mode 100644 index 0000000000000000000000000000000000000000..2df265e8462fb7ae015e47875103b1113eddcf25 --- /dev/null +++ b/ylong_http_client/examples/async_http_multi.rs @@ -0,0 +1,41 @@ +// Copyright (c) 2023 Huawei Device Co., Ltd. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! This is a simple asynchronous HTTP client example using the +//! ylong_http_client crate. It demonstrates creating a client, making a +//! request, and reading the response asynchronously. + +use ylong_http_client::async_impl::{Client, Downloader}; +use ylong_http_client::{HttpClientError, Request}; + +fn main() -> Result<(), HttpClientError> { + let mut handles = Vec::new(); + for _ in 0..4 { + handles.push(ylong_runtime::spawn(async move { + let client = Client::new(); + let request = Request::get("127.0.0.1:3000") + .body("".as_bytes()) + .map_err(|e| HttpClientError::other(Some(e))) + .unwrap(); + // Sends request and receives a `Response`. + let response = client.request(request).await.unwrap(); + + // Reads the body of `Response` by using `BodyReader`. + let _ = Downloader::console(response).download().await; + })) + } + for handle in handles { + let _ = ylong_runtime::block_on(handle); + } + Ok(()) +} diff --git a/ylong_http_client/examples/async_https_outside.rs b/ylong_http_client/examples/async_https_outside.rs index c382823c4cc0bf84488b5501fef0ceab5826ca2b..1fca795ecb734afbc23d8de1237760a7ecf35bb2 100644 --- a/ylong_http_client/examples/async_https_outside.rs +++ b/ylong_http_client/examples/async_https_outside.rs @@ -10,11 +10,13 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - +#[cfg(feature = "tokio_base")] use ylong_http_client::async_impl::{Client, Downloader}; +#[cfg(feature = "tokio_base")] use ylong_http_client::util::Redirect; +#[cfg(feature = "tokio_base")] use ylong_http_client::{Certificate, HttpClientError, Request, TlsVersion}; - +#[cfg(feature = "tokio_base")] fn main() { let rt = tokio::runtime::Builder::new_multi_thread() .enable_all() diff --git a/ylong_http_client/examples/async_proxy_http.rs b/ylong_http_client/examples/async_proxy_http.rs index d59f60215ea0fa4c56190ef53f4d1b77b4c28a7a..8ae11d11716c5b57602ee6a3a86e59d840870ec5 100644 --- a/ylong_http_client/examples/async_proxy_http.rs +++ b/ylong_http_client/examples/async_proxy_http.rs @@ -14,9 +14,12 @@ //! This is a simple asynchronous HTTP client example using the //! ylong_http_client crate. It demonstrates creating a client, making a //! request, and reading the response asynchronously. +#[cfg(feature = "tokio_base")] use ylong_http_client::async_impl::{ClientBuilder, Downloader}; +#[cfg(feature = "tokio_base")] use ylong_http_client::{EmptyBody, HttpClientError, Proxy, Request}; +#[cfg(feature = "tokio_base")] #[tokio::main] async fn main() -> Result<(), HttpClientError> { // Creates a `async_impl::Client` diff --git a/ylong_http_client/examples/async_redirect_http.rs b/ylong_http_client/examples/async_redirect_http.rs index 2f2cf5cffe906aa79d03fa3a464d798334a937a3..9d6ba91732e29c2ddbea4c91ddd454e0eb65f46c 100644 --- a/ylong_http_client/examples/async_redirect_http.rs +++ b/ylong_http_client/examples/async_redirect_http.rs @@ -14,10 +14,11 @@ //! This is a simple asynchronous HTTP client redirect example using the //! ylong_http_client crate. It demonstrates creating a client, making a //! request, and reading the response asynchronously. - +#[cfg(feature = "tokio_base")] use ylong_http_client::async_impl::{ClientBuilder, Downloader}; +#[cfg(feature = "tokio_base")] use ylong_http_client::{HttpClientError, Redirect, Request}; - +#[cfg(feature = "tokio_base")] #[tokio::main] async fn main() -> Result<(), HttpClientError> { // Creates a `async_impl::Client` diff --git a/ylong_http_client/src/async_impl/conn/http2.rs b/ylong_http_client/src/async_impl/conn/http2.rs index 67a65d59e302a66c52493d35feeaefb055dbc5b1..68dc833bb74f749f03d0d46b782933ca63480530 100644 --- a/ylong_http_client/src/async_impl/conn/http2.rs +++ b/ylong_http_client/src/async_impl/conn/http2.rs @@ -455,41 +455,4 @@ mod ut_http2 { Some(H2Error::StreamError(1, ErrorCode::ProtocolError).into()) ); } - - #[cfg(feature = "tokio_base")] - #[test] - fn ut_http2_build_data_frame() { - let mut request = build_request!( - Request: { - Method: "GET", - Uri: "http://127.0.0.1:0/data", - Version: "HTTP/2.0", - Header: "te", "trailers", - Header: "host", "127.0.0.1:0", - Body: "Hi", - } - ); - let rt = tokio::runtime::Builder::new_multi_thread() - .worker_threads(1) - .enable_all() - .build() - .expect("Build runtime failed."); - - rt.block_on(async move { - if let Some(frame) = build_data_frame(1, request.body_mut()) - .await - .expect("build data frame failed") - { - assert_eq!(frame.flags().bits(), 0x1); - assert_eq!(frame.stream_id(), 1); - if let Payload::Data(data) = frame.payload() { - assert_eq!(data.data().as_slice(), "Hi".as_bytes()) - } else { - panic!("err frame type"); - } - } else { - panic!("unexpected data frame build result"); - } - }); - } } diff --git a/ylong_http_client/tests/sdv_async_http.rs b/ylong_http_client/tests/sdv_async_http.rs index 78dd6bd8ec014612885845bf2b7f6bfdc1d12b69..48eda03fcd0f541bc604a8255ad5b890883fc4ca 100644 --- a/ylong_http_client/tests/sdv_async_http.rs +++ b/ylong_http_client/tests/sdv_async_http.rs @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(feature = "async")] +#![cfg(all(feature = "async", feature = "http1_1", feature = "tokio_base"))] #[macro_use] mod common; diff --git a/ylong_http_client/tests/sdv_async_http_on_tcp.rs b/ylong_http_client/tests/sdv_async_http_on_tcp.rs index 96ba103a5b8cb7999feb53662b65ea364782d8e4..c7173dc54ba9479807707145c434e1cf6691f81a 100644 --- a/ylong_http_client/tests/sdv_async_http_on_tcp.rs +++ b/ylong_http_client/tests/sdv_async_http_on_tcp.rs @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(feature = "async")] +#![cfg(all(feature = "async", feature = "http1_1", feature = "ylong_base"))] #[macro_use] pub mod tcp_server; diff --git a/ylong_http_client/tests/sdv_async_https_c_ssl.rs b/ylong_http_client/tests/sdv_async_https_c_ssl.rs index 0cf98c380038ddf7e6eecde24c67c87267af4fa0..68bea9603484dce91b2e6a415714b8810782b08c 100644 --- a/ylong_http_client/tests/sdv_async_https_c_ssl.rs +++ b/ylong_http_client/tests/sdv_async_https_c_ssl.rs @@ -11,7 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(all(feature = "async", feature = "__tls"))] +#![cfg(all( + feature = "async", + feature = "http1_1", + feature = "__tls", + feature = "tokio_base" +))] #[macro_use] mod common; diff --git a/ylong_http_client/tests/sdv_sync_http.rs b/ylong_http_client/tests/sdv_sync_http.rs index 65cf63da39a1a5210ac9a2e36627259b10836b34..6a4ceedfa3d15e1614188975597c2636942335b3 100644 --- a/ylong_http_client/tests/sdv_sync_http.rs +++ b/ylong_http_client/tests/sdv_sync_http.rs @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(feature = "sync")] +#![cfg(all(feature = "sync", feature = "http1_1", feature = "tokio_base"))] #[macro_use] mod common; diff --git a/ylong_http_client/tests/sdv_sync_http_on_tcp.rs b/ylong_http_client/tests/sdv_sync_http_on_tcp.rs index 2d489163e7e2b88733331dd01719d38ee157666c..f78af573d3c3857e37aab1db0ab008a345940e22 100644 --- a/ylong_http_client/tests/sdv_sync_http_on_tcp.rs +++ b/ylong_http_client/tests/sdv_sync_http_on_tcp.rs @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(feature = "sync")] +#![cfg(all(feature = "sync", feature = "http1_1", feature = "ylong_base"))] #[macro_use] mod tcp_server; diff --git a/ylong_http_client/tests/sdv_sync_https_c_ssl.rs b/ylong_http_client/tests/sdv_sync_https_c_ssl.rs index 68bec7fa1318c5ba48ff63ca52d37bde6a3cdd1c..d8389481404d0a8f047329cdfd4d48fb44d140f4 100644 --- a/ylong_http_client/tests/sdv_sync_https_c_ssl.rs +++ b/ylong_http_client/tests/sdv_sync_https_c_ssl.rs @@ -11,7 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(all(feature = "sync", feature = "__tls"))] +#![cfg(all( + feature = "sync", + feature = "http1_1", + feature = "__tls", + feature = "tokio_base" +))] use std::path::PathBuf;