Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebSocket :protocol extension per RFC 9220. #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions h3/src/ext.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Extensions for the HTTP/3 protocol.

use std::convert::TryFrom;

Check warning on line 3 in h3/src/ext.rs

View workflow job for this annotation

GitHub Actions / Test beta ubuntu-latest

the item `TryFrom` is imported redundantly
use std::str::FromStr;

use bytes::{Buf, Bytes};
Expand All @@ -22,13 +22,16 @@
pub const WEB_TRANSPORT: Protocol = Protocol(ProtocolInner::WebTransport);
/// RFC 9298 protocol
pub const CONNECT_UDP: Protocol = Protocol(ProtocolInner::ConnectUdp);
/// RFC 9220 (WebSocket) protocol
pub const WEBSOCKET: Protocol = Protocol(ProtocolInner::WebSocket);

/// 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",
ProtocolInner::WebSocket => "websocket",
}
}
}
Expand All @@ -37,6 +40,7 @@
enum ProtocolInner {
WebTransport,
ConnectUdp,
WebSocket,
}

/// Error when parsing the protocol
Expand All @@ -49,6 +53,7 @@
match s {
"webtransport" => Ok(Self(ProtocolInner::WebTransport)),
"connect-udp" => Ok(Self(ProtocolInner::ConnectUdp)),
"websocket" => Ok(Self(ProtocolInner::WebSocket)),
_ => Err(InvalidProtocol),
}
}
Expand Down
Loading