Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
taikulawo committed Dec 24, 2024
1 parent ee3ab84 commit cb6213c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/frame/reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl Reason {
pub const INADEQUATE_SECURITY: Reason = Reason(12);
/// The endpoint requires that HTTP/1.1 be used instead of HTTP/2.
pub const HTTP_1_1_REQUIRED: Reason = Reason(13);
/// The endpoint requires that HTTP/1.1 be used instead of HTTP/2.
pub const KEEPALIVE_TIMEOUT: Reason = Reason(14);

/// Get a string description of the error code.
pub fn description(&self) -> &str {
Expand All @@ -79,6 +81,7 @@ impl Reason {
11 => "detected excessive load generating behavior",
12 => "security properties do not meet minimum requirements",
13 => "endpoint requires HTTP/1.1",
14 => "keepalive timeout reached",
_ => "unknown reason",
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/proto/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ where
) {
(Some(sleep), _) => {
ready!(sleep.as_mut().poll(cx));
self.inner.as_dyn().go_away_now(Reason::NO_ERROR);
self.inner.as_dyn().go_away_now(Reason::KEEPALIVE_TIMEOUT);
continue 'outer;
}
(None, Some(timeout)) => {
Expand Down
35 changes: 35 additions & 0 deletions tests/h2-tests/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,41 @@ async fn server_builder_set_max_concurrent_streams() {
join(client, h2).await;
}

#[tokio::test]
async fn server_builder_set_keepalive_timeout() {
h2_support::trace_init!();
let (io, mut client) = mock::new();
let h1 = async {
let settings = client.assert_server_handshake().await;
assert_default_settings!(settings);
client
.send_frame(
frames::headers(1)
.request("GET", "https://example.com/")
.eos(),
)
.await;
client
.recv_frame(frames::headers(1).response(200).eos())
.await;
};

let mut builder = server::Builder::new();
builder.keepalive_timeout(Duration::from_secs(2));
let h2 = async move {
let mut srv = builder.handshake::<_, Bytes>(io).await.expect("handshake");
let (req, mut stream) = srv.next().await.unwrap().unwrap();
assert_eq!(req.method(), &http::Method::GET);

let rsp = http::Response::builder().status(200).body(()).unwrap();
let res = stream.send_response(rsp, true).unwrap();
drop(res);
let r1 = srv.accept().await;
println!("rrr {r1:?}");
assert!(r1.is_some_and(|f| f.is_err_and(|f| f.is_go_away())));
};
join(h1, h2).await;
}
#[tokio::test]
async fn serve_request() {
h2_support::trace_init!();
Expand Down

0 comments on commit cb6213c

Please sign in to comment.