Skip to main content

specter/
version.rs

1//! HTTP version configuration.
2
3/// HTTP version preference.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum HttpVersion {
6    /// Force HTTP/1.1.
7    Http1_1,
8    /// Attempt HTTP/2, fallback to HTTP/1.1.
9    Http2,
10    /// Attempt HTTP/3, fallback to HTTP/2, fallback to HTTP/1.1.
11    #[default]
12    Http3,
13    /// HTTP/3 only, no fallback.
14    Http3Only,
15    /// Let the client decide based on server support.
16    Auto,
17}
18
19impl HttpVersion {
20    /// Get human-readable version string.
21    pub fn as_str(&self) -> &'static str {
22        match self {
23            Self::Http1_1 => "HTTP/1.1",
24            Self::Http2 => "HTTP/2",
25            Self::Http3 => "HTTP/3",
26            Self::Http3Only => "HTTP/3 (no fallback)",
27            Self::Auto => "Auto",
28        }
29    }
30
31    /// Check if this version supports multiplexing.
32    pub fn supports_multiplexing(&self) -> bool {
33        matches!(
34            self,
35            Self::Http2 | Self::Http3 | Self::Http3Only | Self::Auto
36        )
37    }
38}