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 #[cfg(feature = "http1_1")] 15 mod http1; 16 17 #[cfg(feature = "http2")] 18 mod http2; 19 20 #[cfg(feature = "http3")] 21 mod http3; 22 23 use crate::async_impl::connector::ConnInfo; 24 use crate::async_impl::request::Message; 25 use crate::async_impl::Response; 26 use crate::error::HttpClientError; 27 use crate::runtime::{AsyncRead, AsyncWrite}; 28 use crate::util::dispatcher::Conn; 29 30 pub(crate) trait StreamData: AsyncRead { shutdownnull31 fn shutdown(&self); 32 is_stream_closablenull33 fn is_stream_closable(&self) -> bool; 34 } 35 36 // TODO: Use structures instead of a function to reuse the io buf. 37 // TODO: Maybe `AsyncWrapper<Conn<S>>` ?. 38 39 pub(crate) async fn request<S>(conn: Conn<S>, message: Message) -> Result<Response, HttpClientError> 40 where 41 S: AsyncRead + AsyncWrite + ConnInfo + Sync + Send + Unpin + 'static, 42 { 43 match conn { 44 #[cfg(feature = "http1_1")] 45 Conn::Http1(http1) => http1::request(http1, message).await, 46 47 #[cfg(feature = "http2")] 48 Conn::Http2(http2) => http2::request(http2, message).await, 49 50 #[cfg(feature = "http3")] 51 Conn::Http3(http3) => http3::request(http3, message).await, 52 } 53 } 54