Handle client-disabled server push (#486)

This commit is contained in:
eggyal
2020-09-18 01:25:31 +01:00
committed by GitHub
parent a19323727b
commit 2b19acf132
6 changed files with 70 additions and 3 deletions

View File

@@ -339,6 +339,11 @@ impl Mock<frame::Settings> {
self.0.set_max_header_list_size(Some(val));
self
}
pub fn disable_push(mut self) -> Self {
self.0.set_enable_push(false);
self
}
}
impl From<Mock<frame::Settings>> for frame::Settings {

View File

@@ -220,6 +220,53 @@ async fn push_request() {
join(client, srv).await;
}
#[tokio::test]
async fn push_request_disabled() {
h2_support::trace_init!();
let (io, mut client) = mock::new();
let client = async move {
client
.assert_server_handshake_with_settings(frames::settings().disable_push())
.await;
client
.send_frame(
frames::headers(1)
.request("GET", "https://example.com/")
.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::GET);
// attempt to push - expect failure
let req = http::Request::builder()
.method("GET")
.uri("https://http2.akamai.com/style.css")
.body(())
.unwrap();
stream
.push_request(req)
.expect_err("push_request should error");
// send normal response
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_against_concurrency() {
h2_support::trace_init!();