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 Protocol extension to Request on Extended CONNECT #655

Merged
merged 1 commit into from Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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!(
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
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