Skip to content

Commit

Permalink
Add Protocol extension to Request on Extended CONNECT (#655)
Browse files Browse the repository at this point in the history
This exposes the :protocol pseudo header as Request extension.

Fixes #347
  • Loading branch information
cloneable committed Jan 20, 2023
1 parent 68e4403 commit b84c244
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/server.rs
Expand Up @@ -1451,8 +1451,13 @@ impl proto::Peer for Peer {
}

let has_protocol = pseudo.protocol.is_some();
if !is_connect && has_protocol {
malformed!("malformed headers: :protocol on non-CONNECT request");
if has_protocol {
if is_connect {
// Assert that we have the right type.
b = b.extension::<crate::ext::Protocol>(pseudo.protocol.unwrap());
} else {
malformed!("malformed headers: :protocol on non-CONNECT request");
}
}

if pseudo.status.is_some() {
Expand Down
7 changes: 6 additions & 1 deletion tests/h2-tests/tests/server.rs
Expand Up @@ -1214,7 +1214,12 @@ async fn extended_connect_protocol_enabled_during_handshake() {

let mut srv = builder.handshake::<_, Bytes>(io).await.expect("handshake");

let (_req, mut stream) = srv.next().await.unwrap().unwrap();
let (req, mut stream) = srv.next().await.unwrap().unwrap();

assert_eq!(
req.extensions().get::<crate::ext::Protocol>(),
Some(&crate::ext::Protocol::from_static("the-bread-protocol"))
);

let rsp = Response::new(());
stream.send_response(rsp, false).unwrap();
Expand Down

0 comments on commit b84c244

Please sign in to comment.