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 use ylong_http::body::async_impl::Body;
15 use ylong_http::request::Request;
16 use ylong_http::response::Response;
17
18 use crate::async_impl::client::Retryable;
19 use crate::async_impl::HttpBody;
20 use crate::error::HttpClientError;
21 use crate::util::dispatcher::Conn;
22 use crate::{AsyncRead, AsyncWrite};
23
24 #[cfg(feature = "http1_1")]
25 mod http1;
26
27 #[cfg(feature = "http2")]
28 mod http2;
29
30 pub(crate) trait StreamData: AsyncRead {
shutdown(&self)31 fn shutdown(&self);
32 }
33
request<S, T>( conn: Conn<S>, request: &mut Request<T>, _retryable: &mut Retryable, ) -> Result<Response<HttpBody>, HttpClientError> where T: Body, S: AsyncRead + AsyncWrite + Sync + Send + Unpin + 'static,34 pub(crate) async fn request<S, T>(
35 conn: Conn<S>,
36 request: &mut Request<T>,
37 _retryable: &mut Retryable,
38 ) -> Result<Response<HttpBody>, HttpClientError>
39 where
40 T: Body,
41 S: AsyncRead + AsyncWrite + Sync + Send + Unpin + 'static,
42 {
43 match conn {
44 #[cfg(feature = "http1_1")]
45 Conn::Http1(http1) => http1::request(http1, request).await,
46
47 #[cfg(feature = "http2")]
48 Conn::Http2(http2) => http2::request(http2, request, _retryable).await,
49 }
50 }
51