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