ntex_h2/frame/
protocol.rs

1//! Extensions specific to the HTTP/2 protocol.
2use std::fmt;
3
4use ntex_bytes::ByteString;
5
6/// Represents the `:protocol` pseudo-header used by
7/// the [Extended CONNECT Protocol].
8///
9/// [Extended CONNECT Protocol]: https://datatracker.ietf.org/doc/html/rfc8441#section-4
10#[derive(Clone, Eq, PartialEq)]
11pub struct Protocol {
12    value: ByteString,
13}
14
15impl Protocol {
16    /// Converts a static string to a protocol name.
17    pub const fn from_static(value: &'static str) -> Self {
18        Self {
19            value: ByteString::from_static(value),
20        }
21    }
22
23    /// Returns a str representation of the header.
24    #[inline]
25    pub fn as_str(&self) -> &str {
26        self.value.as_ref()
27    }
28}
29
30impl<'a> From<&'a str> for Protocol {
31    fn from(value: &'a str) -> Self {
32        Self {
33            value: ByteString::from(value),
34        }
35    }
36}
37
38impl From<ByteString> for Protocol {
39    fn from(value: ByteString) -> Self {
40        Protocol { value }
41    }
42}
43
44impl From<Protocol> for ByteString {
45    fn from(proto: Protocol) -> Self {
46        proto.value
47    }
48}
49
50impl AsRef<[u8]> for Protocol {
51    fn as_ref(&self) -> &[u8] {
52        self.value.as_bytes()
53    }
54}
55
56impl fmt::Debug for Protocol {
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        self.value.fmt(f)
59    }
60}