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