From 8b35a946d9f6b31b26b9783acbfab984316051f4 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 23 Feb 2024 17:09:47 +0100 Subject: [PATCH] Allow external HTTP client --- src/k2v-client/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs index 852274a7..5b6d7f58 100644 --- a/src/k2v-client/lib.rs +++ b/src/k2v-client/lib.rs @@ -72,6 +72,16 @@ impl K2vClient { .enable_http2() .build(); let client = HttpClient::builder(TokioExecutor::new()).build(connector); + Self::new_with_client(config, client) + } + + /// Create a new K2V client with an external client. + /// Useful for example if you plan on creating many clients but you want to mutualize the + /// underlying thread pools & co. + pub fn new_with_client( + config: K2vClientConfig, + client: HttpClient, Body>, + ) -> Result { let user_agent: std::borrow::Cow = match &config.user_agent { Some(ua) => ua.into(), None => format!("k2v/{}", env!("CARGO_PKG_VERSION")).into(), -- 2.45.2