From e5bcbcc7a4f3ea2bfa5d52e8896433ff055b8c5d Mon Sep 17 00:00:00 2001 From: hson Date: Wed, 11 May 2022 21:18:58 +0900 Subject: [PATCH 1/4] Expose hyper HTTP2 keep-alive config. --- src/async_impl/client.rs | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 85df20947..b6595f925 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -110,6 +110,9 @@ struct Config { http2_initial_connection_window_size: Option, http2_adaptive_window: bool, http2_max_frame_size: Option, + http2_keep_alive_interval: Option, + http2_keep_alive_timeout: Option, + http2_keep_alive_while_idle: bool, local_address: Option, nodelay: bool, #[cfg(feature = "cookies")] @@ -175,6 +178,9 @@ impl ClientBuilder { http2_initial_connection_window_size: None, http2_adaptive_window: false, http2_max_frame_size: None, + http2_keep_alive_interval: None, + http2_keep_alive_timeout: None, + http2_keep_alive_while_idle: false, local_address: None, nodelay: true, trust_dns: cfg!(feature = "trust-dns"), @@ -476,6 +482,15 @@ impl ClientBuilder { if let Some(http2_max_frame_size) = config.http2_max_frame_size { builder.http2_max_frame_size(http2_max_frame_size); } + if let Some(http2_keep_alive_interval) = config.http2_keep_alive_interval { + builder.http2_keep_alive_interval(http2_keep_alive_interval); + } + if let Some(http2_keep_alive_timeout) = config.http2_keep_alive_timeout { + builder.http2_keep_alive_timeout(http2_keep_alive_timeout); + } + if config.http2_keep_alive_while_idle { + builder.http2_keep_alive_while_idle(true); + } builder.pool_idle_timeout(config.pool_idle_timeout); builder.pool_max_idle_per_host(config.pool_max_idle_per_host); @@ -935,6 +950,36 @@ impl ClientBuilder { self } + /// Sets an interval for HTTP2 Ping frames should be sent to keep a connection alive. + /// + /// Pass `None` to disable HTTP2 keep-alive. + /// Default is currently disabled. + pub fn http2_keep_alive_interval(mut self, interval: impl Into>) -> ClientBuilder { + self.config.http2_keep_alive_interval = interval.into(); + self + } + + /// Sets a timeout for receiving an acknowledgement of the keep-alive ping. + /// + /// If the ping is not acknowledged within the timeout, the connection will be closed. + /// Does nothing if `http2_keep_alive_interval` is disabled. + /// Default is currently disabled. + pub fn http2_keep_alive_timeout(mut self, timeout: Duration) -> ClientBuilder { + self.config.http2_keep_alive_timeout = Some(timeout); + self + } + + /// Sets whether HTTP2 keep-alive should apply while the connection is idle. + /// + /// If disabled, keep-alive pings are only sent while there are open request/responses streams. + /// If enabled, pings are also sent when no streams are active. + /// Does nothing if `http2_keep_alive_interval` is disabled. + /// Default is `false`. + pub fn http2_keep_alive_while_idle(mut self, enabled: bool) -> ClientBuilder { + self.config.http2_keep_alive_while_idle = enabled; + self + } + // TCP options /// Set whether sockets have `SO_NODELAY` enabled. From bd92277bf5d61e2d3e746f5e3f2c5011b06ca9b3 Mon Sep 17 00:00:00 2001 From: hson Date: Thu, 12 May 2022 02:08:32 +0900 Subject: [PATCH 2/4] fix style and format --- src/async_impl/client.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index b6595f925..6f10139f6 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -954,11 +954,14 @@ impl ClientBuilder { /// /// Pass `None` to disable HTTP2 keep-alive. /// Default is currently disabled. - pub fn http2_keep_alive_interval(mut self, interval: impl Into>) -> ClientBuilder { + pub fn http2_keep_alive_interval( + mut self, + interval: impl Into>, + ) -> ClientBuilder { self.config.http2_keep_alive_interval = interval.into(); self } - + /// Sets a timeout for receiving an acknowledgement of the keep-alive ping. /// /// If the ping is not acknowledged within the timeout, the connection will be closed. @@ -968,7 +971,7 @@ impl ClientBuilder { self.config.http2_keep_alive_timeout = Some(timeout); self } - + /// Sets whether HTTP2 keep-alive should apply while the connection is idle. /// /// If disabled, keep-alive pings are only sent while there are open request/responses streams. From 336056300bc1b6a7aa5f800c7f37550f63c6349a Mon Sep 17 00:00:00 2001 From: hson Date: Thu, 12 May 2022 04:03:56 +0900 Subject: [PATCH 3/4] Bump async-compression --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b2b9989eb..14d5150df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -127,7 +127,7 @@ cookie_store = { version = "0.16", optional = true } proc-macro-hack = { version = "0.5.19", optional = true } ## compression -async-compression = { version = "0.3.7", default-features = false, features = ["tokio"], optional = true } +async-compression = { version = "0.3.13", default-features = false, features = ["tokio"], optional = true } tokio-util = { version = "0.7.1", default-features = false, features = ["codec", "io"], optional = true } ## socks From 6e1a026c6079d5fa88a4dba56ca4a346468e70ca Mon Sep 17 00:00:00 2001 From: hson Date: Thu, 12 May 2022 04:10:08 +0900 Subject: [PATCH 4/4] Update path and toolchain up to date --- .github/workflows/ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b304a91c..6bb17c1c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -165,6 +165,25 @@ jobs: profile: minimal override: true + - name: Add mingw32 to path for i686-gnu + run: | + echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH + echo "C:\msys64\usr\bin" >> $GITHUB_PATH + if: matrix.target == 'i686-pc-windows-gnu' + shell: bash + - name: Add mingw64 to path for x86_64-gnu + run: | + echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH + echo "C:\msys64\usr\bin" >> $GITHUB_PATH + if: matrix.target == 'x86_64-pc-windows-gnu' + shell: bash + - name: Update gcc + if: matrix.target == 'x86_64-pc-windows-gnu' + run: pacman.exe -Sy --noconfirm mingw-w64-x86_64-toolchain + - name: Update gcc + if: matrix.target == 'i686-pc-windows-gnu' + run: pacman.exe -Sy --noconfirm mingw-w64-i686-toolchain + - name: Build uses: actions-rs/cargo@v1 with: