Skip to content

Commit ac93a8e

Browse files
committed
docs(ext): improve docs for Protocol ext
1 parent 619ecf0 commit ac93a8e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/ext/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,26 @@ pub(crate) use informational::OnInformational;
6262
#[cfg(all(feature = "http1", feature = "client", feature = "ffi"))]
6363
pub(crate) use informational::{on_informational_raw, OnInformationalCallback};
6464

65+
6566
#[cfg(feature = "http2")]
66-
/// Represents the `:protocol` pseudo-header used by
67-
/// the [Extended CONNECT Protocol].
67+
/// Extension type representing the `:protocol` pseudo-header in HTTP/2.
68+
///
69+
/// The `Protocol` extension allows access to the value of the `:protocol` pseudo-header
70+
/// used by the [Extended CONNECT Protocol](https://datatracker.ietf.org/doc/html/rfc8441#section-4).
71+
/// This extension is only sent on HTTP/2 CONNECT requests, most commonly with the value `websocket`.
72+
///
73+
/// # Example
6874
///
69-
/// [Extended CONNECT Protocol]: https://datatracker.ietf.org/doc/html/rfc8441#section-4
75+
/// ```rust
76+
/// use hyper::ext::Protocol;
77+
/// use http::{Request, Method, Version};
78+
///
79+
/// let mut req = Request::new(());
80+
/// *req.method_mut() = Method::CONNECT;
81+
/// *req.version_mut() = Version::HTTP_2;
82+
/// req.extensions_mut().insert(Protocol::from_static("websocket"));
83+
/// // Now the request will include the `:protocol` pseudo-header with value "websocket"
84+
/// ```
7085
#[derive(Clone, Eq, PartialEq)]
7186
pub struct Protocol {
7287
inner: h2::ext::Protocol,

0 commit comments

Comments
 (0)