From 1c2b59e9f8b4df20bd88550c19271c56eb3ced92 Mon Sep 17 00:00:00 2001 From: Tyler Beckman Date: Sun, 27 Oct 2024 16:11:47 -0600 Subject: [PATCH] feat(api): Allow re-use of existing reqwest client in CtApiClient struct --- src/api/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index d153df8..69204c3 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use reqwest::Url; use responses::{ AddChainRequest, @@ -11,18 +13,25 @@ pub mod endpoints; pub mod responses; pub struct CtApiClient { - inner_client: reqwest::Client, + inner_client: Arc, log_url: Url } impl CtApiClient { pub fn new(log_url: Url) -> reqwest::Result { Ok(Self { - inner_client: reqwest::Client::builder().https_only(true).build()?, + inner_client: Arc::new(reqwest::Client::builder().https_only(true).build()?), log_url }) } + pub fn new_with_client(log_url: Url, inner_client: Arc) -> Self { + Self { + inner_client, + log_url + } + } + /// Adds a standard x509 chain to the CT log. The log will then return /// information needed to construct a valid SCT entry, including timestamp, /// CT log signature, sct version, and any log operator extensions.