Test CONNECT is accepted

This commit is contained in:
Kornel Lesiński
2020-03-09 17:35:32 +00:00
committed by Sean McArthur
parent f7b3cf6d29
commit 5041a4d428
2 changed files with 50 additions and 0 deletions

View File

@@ -113,6 +113,25 @@ impl Mock<frame::Headers> {
Mock(frame)
}
pub fn method<M>(self, method: M) -> Self
where
M: TryInto<http::Method>,
M::Error: fmt::Debug,
{
let method = method.try_into().unwrap();
let (id, _, fields) = self.into_parts();
let frame = frame::Headers::new(
id,
frame::Pseudo {
scheme: None,
method: Some(method),
..Default::default()
},
fields,
);
Mock(frame)
}
pub fn response<S>(self, status: S) -> Self
where
S: TryInto<http::StatusCode>,

View File

@@ -105,6 +105,37 @@ async fn serve_request() {
join(client, srv).await;
}
#[tokio::test]
async fn serve_connect() {
let _ = env_logger::try_init();
let (io, mut client) = mock::new();
let client = async move {
let settings = client.assert_server_handshake().await;
assert_default_settings!(settings);
client
.send_frame(frames::headers(1).method("CONNECT").eos())
.await;
client
.recv_frame(frames::headers(1).response(200).eos())
.await;
};
let srv = async move {
let mut srv = server::handshake(io).await.expect("handshake");
let (req, mut stream) = srv.next().await.unwrap().unwrap();
assert_eq!(req.method(), &http::Method::CONNECT);
let rsp = http::Response::builder().status(200).body(()).unwrap();
stream.send_response(rsp, true).unwrap();
assert!(srv.next().await.is_none());
};
join(client, srv).await;
}
#[tokio::test]
async fn push_request() {
let _ = env_logger::try_init();