use super::*;
impl ServerProtocol {
#[inline(always)]
pub fn get_alpn_protocol(&self) -> &'static [u8] {
match self {
Self::Http1 => ALPN_HTTP1,
Self::Http2 => ALPN_HTTP2,
Self::Http3 => ALPN_HTTP3,
}
}
#[inline(always)]
pub fn get_version(&self) -> HttpVersion {
match self {
Self::Http1 => HttpVersion::Http1_1,
Self::Http2 => HttpVersion::Http2,
Self::Http3 => HttpVersion::Http3,
}
}
#[inline(always)]
pub fn is_quic(&self) -> bool {
matches!(self, Self::Http3)
}
}
impl Default for ServerConfig {
#[inline(always)]
fn default() -> Self {
Self {
address: Server::format_bind_address(DEFAULT_HOST, DEFAULT_WEB_PORT),
nodelay: DEFAULT_NODELAY,
ttl: DEFAULT_TTI,
protocol: ServerProtocol::default(),
tls: None,
}
}
}
impl ServerConfig {
pub fn from_json<C>(json: C) -> Result<Self, serde_json::Error>
where
C: AsRef<str>,
{
serde_json::from_str(json.as_ref())
}
#[inline(always)]
pub fn get_alpn_protocol(&self) -> &'static [u8] {
self.get_protocol().get_alpn_protocol()
}
}