deboa_compio/client/http/
http1.rs1use crate::client::http::conn::{BaseHttpConnection, Http1Connection};
2use compio::net::TcpStream;
3use cyper_core::HyperStream;
4use deboa::{
5 conn::{HttpConnection, ProtoConnection},
6 errors::{ConnectionError, DeboaError},
7 request::Http1Request,
8 Result,
9};
10use http::version::Version;
11use hyper::client::conn::http1::handshake;
12
13impl HttpConnection for Http1Connection {
14 type Sender = Http1Request;
15 fn sender(&mut self) -> &mut Self::Sender {
16 &mut self.sender
17 }
18}
19
20impl ProtoConnection for Http1Connection {
21 type Connection = Http1Connection;
22 type RuntimeStream = HyperStream<TcpStream>;
23
24 #[inline]
25 fn protocol_version(&self) -> Version {
26 Version::HTTP_11
27 }
28
29 async fn connect(stream: Self::RuntimeStream) -> Result<Self::Connection> {
30 let (sender, conn) = handshake(stream)
31 .await
32 .map_err(|e| {
33 DeboaError::Connection(ConnectionError::Handshake { message: e.to_string() })
34 })?;
35
36 compio::runtime::spawn(async move {
37 match conn
38 .with_upgrades()
39 .await
40 {
41 Ok(_) => (),
42 Err(err) => {
43 log::error!("Error: {:#}", err)
44 }
45 };
46 })
47 .detach();
48
49 Ok(BaseHttpConnection::new(sender))
50 }
51}