pub(crate) const HTTP_UPGRADE_PROTOCOL: &str = "iroh derp http";
pub(crate) const WEBSOCKET_UPGRADE_PROTOCOL: &str = "websocket";
#[cfg(feature = "iroh-relay")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
pub(crate) const SUPPORTED_WEBSOCKET_VERSION: &str = "13";
pub const RELAY_PATH: &str = "/relay";
pub const RELAY_PROBE_PATH: &str = "/relay/probe";
#[cfg(feature = "iroh-relay")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
pub(crate) const LEGACY_RELAY_PATH: &str = "/derp";
#[cfg(feature = "iroh-relay")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
pub(crate) const LEGACY_RELAY_PROBE_PATH: &str = "/derp/probe";
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Protocol {
Relay,
Websocket,
}
impl Protocol {
pub const fn upgrade_header(&self) -> &'static str {
match self {
Protocol::Relay => HTTP_UPGRADE_PROTOCOL,
Protocol::Websocket => WEBSOCKET_UPGRADE_PROTOCOL,
}
}
pub fn parse_header(header: &http::HeaderValue) -> Option<Self> {
let header_bytes = header.as_bytes();
if header_bytes == Protocol::Relay.upgrade_header().as_bytes() {
Some(Protocol::Relay)
} else if header_bytes == Protocol::Websocket.upgrade_header().as_bytes() {
Some(Protocol::Websocket)
} else {
None
}
}
}