Skip to content

Commit d97181a

Browse files
Added with upgrades to auto serve connection (#38)
1 parent eacb82d commit d97181a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/server/conn/auto.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ impl<E> Builder<E> {
8686

8787
Ok(())
8888
}
89+
90+
/// Bind a connection together with a [`Service`], with the ability to
91+
/// handle HTTP upgrades. This requires that the IO object implements
92+
/// `Send`.
93+
pub async fn serve_connection_with_upgrades<I, S, B>(&self, io: I, service: S) -> Result<()>
94+
where
95+
S: Service<Request<Incoming>, Response = Response<B>> + Send,
96+
S::Future: Send + 'static,
97+
S::Error: Into<Box<dyn StdError + Send + Sync>>,
98+
B: Body + Send + 'static,
99+
B::Data: Send,
100+
B::Error: Into<Box<dyn StdError + Send + Sync>>,
101+
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
102+
E: Http2ConnExec<S::Future, B>,
103+
{
104+
let (version, io) = read_version(io).await?;
105+
let io = TokioIo::new(io);
106+
match version {
107+
Version::H1 => {
108+
self.http1
109+
.serve_connection(io, service)
110+
.with_upgrades()
111+
.await?
112+
}
113+
Version::H2 => self.http2.serve_connection(io, service).await?,
114+
}
115+
116+
Ok(())
117+
}
89118
}
90119
#[derive(Copy, Clone)]
91120
enum Version {

0 commit comments

Comments
 (0)