From ce7524adcc312aba4d79b9c72c561d97fb9b7eee Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 10 Jul 2023 22:01:28 -0400 Subject: [PATCH 1/2] Add support for RFC 9298 in :protocol extension --- h3/src/ext.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/h3/src/ext.rs b/h3/src/ext.rs index 9c42f441..6e1ec900 100644 --- a/h3/src/ext.rs +++ b/h3/src/ext.rs @@ -20,11 +20,14 @@ pub struct Protocol(ProtocolInner); impl Protocol { /// WebTransport protocol pub const WEB_TRANSPORT: Protocol = Protocol(ProtocolInner::WebTransport); + /// RFC 9298 protocol + pub const CONNECT_UDP: Protocol = Protocol(ProtocolInner::ConnectUdp); } #[derive(Copy, PartialEq, Debug, Clone)] enum ProtocolInner { WebTransport, + ConnectUdp, } /// Error when parsing the protocol @@ -36,6 +39,7 @@ impl FromStr for Protocol { fn from_str(s: &str) -> Result { match s { "webtransport" => Ok(Self(ProtocolInner::WebTransport)), + "connect-udp" => Ok(Self(ProtocolInner::ConnectUdp)), _ => Err(InvalidProtocol), } } From 0dffc9008f65dc0aea272623a5f17c38df37f737 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 10 Jul 2023 22:04:19 -0400 Subject: [PATCH 2/2] bugfix: Properly encode :protocol header Previously, the `:protocol` header wouldn't be set when the `Protocol` extension was active for a `Request`. This was most likely because the Webtransport PR (the PR that introduced the `Protocol` extension) did not include a client implementation and thus did not test this. --- h3/src/ext.rs | 9 +++++++++ h3/src/proto/headers.rs | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/h3/src/ext.rs b/h3/src/ext.rs index 6e1ec900..ff1f0e58 100644 --- a/h3/src/ext.rs +++ b/h3/src/ext.rs @@ -22,6 +22,15 @@ impl Protocol { pub const WEB_TRANSPORT: Protocol = Protocol(ProtocolInner::WebTransport); /// RFC 9298 protocol pub const CONNECT_UDP: Protocol = Protocol(ProtocolInner::ConnectUdp); + + /// Return a &str representation of the `:protocol` pseudo-header value + #[inline] + pub fn as_str(&self) -> &str { + match self.0 { + ProtocolInner::WebTransport => "webtransport", + ProtocolInner::ConnectUdp => "connect-udp", + } + } } #[derive(Copy, PartialEq, Debug, Clone)] diff --git a/h3/src/proto/headers.rs b/h3/src/proto/headers.rs index 5a4bda13..c9b15a66 100644 --- a/h3/src/proto/headers.rs +++ b/h3/src/proto/headers.rs @@ -181,6 +181,10 @@ impl Iterator for HeaderIter { if let Some(status) = pseudo.status.take() { return Some((":status", status.as_str()).into()); } + + if let Some(protocol) = pseudo.protocol.take() { + return Some((":protocol", protocol.as_str().as_bytes()).into()); + } } self.pseudo = None;