Skip to content

Commit b84c244

Browse files
authored
Add Protocol extension to Request on Extended CONNECT (#655)
This exposes the :protocol pseudo header as Request extension. Fixes #347
1 parent 68e4403 commit b84c244

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/server.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,13 @@ impl proto::Peer for Peer {
14511451
}
14521452

14531453
let has_protocol = pseudo.protocol.is_some();
1454-
if !is_connect && has_protocol {
1455-
malformed!("malformed headers: :protocol on non-CONNECT request");
1454+
if has_protocol {
1455+
if is_connect {
1456+
// Assert that we have the right type.
1457+
b = b.extension::<crate::ext::Protocol>(pseudo.protocol.unwrap());
1458+
} else {
1459+
malformed!("malformed headers: :protocol on non-CONNECT request");
1460+
}
14561461
}
14571462

14581463
if pseudo.status.is_some() {

tests/h2-tests/tests/server.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,12 @@ async fn extended_connect_protocol_enabled_during_handshake() {
12141214

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

1217-
let (_req, mut stream) = srv.next().await.unwrap().unwrap();
1217+
let (req, mut stream) = srv.next().await.unwrap().unwrap();
1218+
1219+
assert_eq!(
1220+
req.extensions().get::<crate::ext::Protocol>(),
1221+
Some(&crate::ext::Protocol::from_static("the-bread-protocol"))
1222+
);
12181223

12191224
let rsp = Response::new(());
12201225
stream.send_response(rsp, false).unwrap();

0 commit comments

Comments
 (0)