diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-02-23 17:09:47 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-02-23 17:09:47 +0100 |
commit | 8b35a946d9f6b31b26b9783acbfab984316051f4 (patch) | |
tree | 41480d1485dee1fd4c7736097683dbfc3237cca4 | |
parent | 61758ce0f91b930542bd2ee3c72735000cc12e75 (diff) | |
download | garage-k2v/shared_http_client.tar.gz garage-k2v/shared_http_client.zip |
Allow external HTTP clientk2v/shared_http_client
-rw-r--r-- | src/k2v-client/lib.rs | 10 |
1 files changed, 10 insertions, 0 deletions
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<HttpsConnector<HttpConnector>, Body>, + ) -> Result<Self, Error> { let user_agent: std::borrow::Cow<str> = match &config.user_agent { Some(ua) => ua.into(), None => format!("k2v/{}", env!("CARGO_PKG_VERSION")).into(), |