From bd7ce772f833b795cb2443d593e0f4edb9470c7b Mon Sep 17 00:00:00 2001 From: liuziheng Date: Thu, 7 Sep 2023 10:23:42 +0800 Subject: [PATCH] tokio->ylong_runtime Signed-off-by: liuziheng --- ylong_http/BUILD.gn | 15 +++++- ylong_http/src/body/chunk.rs | 4 +- ylong_http/src/body/empty.rs | 12 +++-- ylong_http/src/body/mime/common/mix.rs | 52 ++++++++++++++----- ylong_http/src/body/mime/encode/multi.rs | 13 +++-- ylong_http/src/body/mime/encode/part.rs | 36 +++++++++---- ylong_http/src/body/mime/mod.rs | 24 ++++++--- ylong_http/src/body/mod.rs | 13 +++-- ylong_http/src/body/text.rs | 24 ++++++--- ylong_http_client/BUILD.gn | 10 +++- ylong_http_client/Cargo.toml | 39 +++----------- ylong_http_client/examples/async_http.rs | 12 ++++- ylong_http_client/examples/async_http2.rs | 4 +- .../examples/async_http2_multi.rs | 6 ++- .../examples/async_http_multi.rs | 41 +++++++++++++++ .../examples/async_https_outside.rs | 6 ++- .../examples/async_proxy_http.rs | 3 ++ .../examples/async_redirect_http.rs | 5 +- .../src/async_impl/conn/http2.rs | 37 ------------- ylong_http_client/tests/sdv_async_http.rs | 2 +- .../tests/sdv_async_http_on_tcp.rs | 2 +- .../tests/sdv_async_https_c_ssl.rs | 7 ++- ylong_http_client/tests/sdv_sync_http.rs | 2 +- .../tests/sdv_sync_http_on_tcp.rs | 2 +- .../tests/sdv_sync_https_c_ssl.rs | 7 ++- 25 files changed, 245 insertions(+), 133 deletions(-) create mode 100644 ylong_http_client/examples/async_http_multi.rs diff --git a/ylong_http/BUILD.gn b/ylong_http/BUILD.gn index 3e84ba6..abfa89f 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 c711531..8b3ec35 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 852677f..0f9f9d0 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 6095f0a..b4da95a 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 0e722af..a0c35fb 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 43b3376..854d0e6 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 ea6d7c8..d1635b4 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 0bc031b..60b3baa 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 d39519e..e3b82b7 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 53d055e..6b21477 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 e507b3d..9ede293 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 a6edc7b..d713535 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 0d16c7b..f53e899 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 8886b20..4c60e42 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 0000000..2df265e --- /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 c382823..1fca795 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 d59f602..8ae11d1 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 2f2cf5c..9d6ba91 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 67a65d5..68dc833 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 78dd6bd..48eda03 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 96ba103..c7173dc 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 0cf98c3..68bea96 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 65cf63d..6a4ceed 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 2d48916..f78af57 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 68bec7f..d838948 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; -- Gitee