From 0c187a3db29fe3d157898fd48fe9f398c37bf67b Mon Sep 17 00:00:00 2001 From: John Howard Date: Wed, 15 Nov 2023 12:07:59 -0800 Subject: [PATCH] client: add timer() option (#25) Currently, a timer must be provided to use http2. However, this has no option to actually configure this. This PR introduces a new function to set the timer. With this, I am able to successfully make HTTP2 calls with the Client. --- src/client/legacy.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/client/legacy.rs b/src/client/legacy.rs index 1d2dae8..4b899b3 100644 --- a/src/client/legacy.rs +++ b/src/client/legacy.rs @@ -14,6 +14,7 @@ use std::time::Duration; use futures_util::future::{self, Either, FutureExt, TryFutureExt}; use http::uri::Scheme; use hyper::header::{HeaderValue, HOST}; +use hyper::rt::Timer; use hyper::{body::Body, Method, Request, Response, Uri, Version}; use tracing::{debug, trace, warn}; @@ -1349,6 +1350,22 @@ impl Builder { self } + /// Provide a timer to be used for timeouts and intervals. + /// + /// See the documentation of [`h2::client::Builder::timer`] for more + /// details. + /// + /// [`h2::client::Builder::timer`]: https://docs.rs/h2/client/struct.Builder.html#method.timer + pub fn timer(&mut self, timer: M) -> &mut Self + where + M: Timer + Send + Sync + 'static, + { + #[cfg(feature = "http2")] + self.h2_builder.timer(timer); + // TODO(https://github.com/hyperium/hyper/issues/3167) set for pool as well + self + } + /// Set the maximum write buffer size for each HTTP/2 stream. /// /// Default is currently 1MB, but may change.