1pub(crate) const HTTP_UPGRADE_PROTOCOL: &str = "iroh derp http";
4pub(crate) const WEBSOCKET_UPGRADE_PROTOCOL: &str = "websocket";
5#[cfg(feature = "iroh-relay")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
7pub(crate) const SUPPORTED_WEBSOCKET_VERSION: &str = "13";
8
9pub const RELAY_PATH: &str = "/relay";
12pub const RELAY_PROBE_PATH: &str = "/relay/probe";
14#[cfg(feature = "iroh-relay")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
18pub(crate) const LEGACY_RELAY_PATH: &str = "/derp";
19#[cfg(feature = "iroh-relay")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
23pub(crate) const LEGACY_RELAY_PROBE_PATH: &str = "/derp/probe";
24
25#[derive(Debug, Copy, Clone, PartialEq, Eq)]
27pub enum Protocol {
28 Relay,
30 Websocket,
34}
35
36impl Protocol {
37 pub const fn upgrade_header(&self) -> &'static str {
39 match self {
40 Protocol::Relay => HTTP_UPGRADE_PROTOCOL,
41 Protocol::Websocket => WEBSOCKET_UPGRADE_PROTOCOL,
42 }
43 }
44
45 pub fn parse_header(header: &http::HeaderValue) -> Option<Self> {
47 let header_bytes = header.as_bytes();
48 if header_bytes == Protocol::Relay.upgrade_header().as_bytes() {
49 Some(Protocol::Relay)
50 } else if header_bytes == Protocol::Websocket.upgrade_header().as_bytes() {
51 Some(Protocol::Websocket)
52 } else {
53 None
54 }
55 }
56}