Skip to content

Commit 26e1e15

Browse files
authored
feat(server): expose methods for determining if HTTP/1.1 or HTTP/2 support are enabled (#164)
1 parent 0c402d8 commit 26e1e15

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/server/conn/auto/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ impl<E> Builder<E> {
131131
self
132132
}
133133

134+
/// Returns `true` if this builder can serve an HTTP/1.1-based connection.
135+
pub fn is_http1_available(&self) -> bool {
136+
match self.version {
137+
#[cfg(feature = "http1")]
138+
Some(Version::H1) => true,
139+
#[cfg(feature = "http2")]
140+
Some(Version::H2) => false,
141+
#[cfg(any(feature = "http1", feature = "http2"))]
142+
_ => true,
143+
}
144+
}
145+
146+
/// Returns `true` if this builder can serve an HTTP/2-based connection.
147+
pub fn is_http2_available(&self) -> bool {
148+
match self.version {
149+
#[cfg(feature = "http1")]
150+
Some(Version::H1) => false,
151+
#[cfg(feature = "http2")]
152+
Some(Version::H2) => true,
153+
#[cfg(any(feature = "http1", feature = "http2"))]
154+
_ => true,
155+
}
156+
}
157+
134158
/// Bind a connection together with a [`Service`].
135159
pub fn serve_connection<I, S, B>(&self, io: I, service: S) -> Connection<'_, I, S, E>
136160
where

0 commit comments

Comments
 (0)