1use core::fmt;
2
3use xitca_service::Service;
4
5use crate::builder::{HttpServiceBuilder, marker};
6
7use super::service::H1Service;
8
9impl<St, FA, const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize>
10 HttpServiceBuilder<marker::Http1, St, FA, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>
11{
12 #[cfg(unix)]
13 pub fn unix(
15 self,
16 ) -> HttpServiceBuilder<marker::Http1, xitca_io::net::UnixStream, FA, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>
17 where
18 FA: Service,
19 {
20 HttpServiceBuilder {
21 tls_factory: self.tls_factory,
22 config: self.config,
23 _body: std::marker::PhantomData,
24 }
25 }
26
27 #[cfg(feature = "io-uring")]
28 pub fn io_uring(
30 self,
31 ) -> HttpServiceBuilder<
32 marker::Http1Uring,
33 xitca_io::net::io_uring::TcpStream,
34 FA,
35 HEADER_LIMIT,
36 READ_BUF_LIMIT,
37 WRITE_BUF_LIMIT,
38 >
39 where
40 FA: Service,
41 {
42 HttpServiceBuilder {
43 tls_factory: self.tls_factory,
44 config: self.config,
45 _body: std::marker::PhantomData,
46 }
47 }
48}
49
50type Error = Box<dyn fmt::Debug>;
51
52impl<St, FA, S, E, const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize>
53 Service<Result<S, E>> for HttpServiceBuilder<marker::Http1, St, FA, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>
54where
55 FA: Service,
56 FA::Error: fmt::Debug + 'static,
57 E: fmt::Debug + 'static,
58{
59 type Response = H1Service<St, S, FA::Response, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>;
60 type Error = Error;
61
62 async fn call(&self, res: Result<S, E>) -> Result<Self::Response, Self::Error> {
63 let service = res.map_err(|e| Box::new(e) as Error)?;
64 let tls_acceptor = self.tls_factory.call(()).await.map_err(|e| Box::new(e) as Error)?;
65 Ok(H1Service::new(self.config, service, tls_acceptor))
66 }
67}
68
69#[cfg(feature = "io-uring")]
70impl<St, FA, S, E, const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize>
71 Service<Result<S, E>>
72 for HttpServiceBuilder<marker::Http1Uring, St, FA, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>
73where
74 FA: Service,
75 FA::Error: fmt::Debug + 'static,
76 E: fmt::Debug + 'static,
77{
78 type Response = super::service::H1UringService<S, FA::Response, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>;
79 type Error = Error;
80
81 async fn call(&self, res: Result<S, E>) -> Result<Self::Response, Self::Error> {
82 let service = res.map_err(|e| Box::new(e) as Error)?;
83 let tls_acceptor = self.tls_factory.call(()).await.map_err(|e| Box::new(e) as Error)?;
84 Ok(super::service::H1UringService::new(self.config, service, tls_acceptor))
85 }
86}