async_http_client_lite/
client_ext.rs1use std::io;
2
3use futures_io::{AsyncRead, AsyncWrite};
4use http::{Request, Response, Version};
5
6#[cfg(feature = "h1__async_http1_lite")]
8use async_http1_lite::Http1ClientStream as AsyncHttp1LiteHttp1ClientStream;
9
10use crate::client::Client;
12
13pub enum ClientBackendKind {
17 #[cfg(feature = "h1__async_http1_lite")]
18 H1AsyncHttp1Lite,
19}
20
21impl<S> Client<S>
22where
23 S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
24{
25 pub async fn response(
26 &mut self,
27 request: Request<Vec<u8>>,
28 backend_kind: ClientBackendKind,
29 ) -> io::Result<(Response<Vec<u8>>, Option<Vec<u8>>)> {
30 if request.version() <= Version::HTTP_11 {
31 match backend_kind {
32 #[cfg(feature = "h1__async_http1_lite")]
33 ClientBackendKind::H1AsyncHttp1Lite => {
34 let mut stream = AsyncHttp1LiteHttp1ClientStream::new(self.get_mut());
35 stream.write_request(request).await?;
36
37 let (response, reason_phrase) = stream.read_response().await?;
38
39 Ok((response, reason_phrase))
40 }
41 }
42 } else if request.version() <= Version::HTTP_2 {
43 return Err(io::Error::new(io::ErrorKind::Other, "unimplemented now"));
45 } else {
46 return Err(io::Error::new(io::ErrorKind::Other, "unimplemented now"));
47 }
48 }
49}
50
51impl<S> Client<S>
55where
56 S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
57{
58 #[cfg(feature = "h1__async_http1_lite")]
59 pub fn into_async_http1_lite(self) -> io::Result<AsyncHttp1LiteHttp1ClientStream<S>> {
60 Ok(AsyncHttp1LiteHttp1ClientStream::new(self.into_inner()))
61 }
62}