From 7aeaed381dfd7071bceb6830449b33697f26152e Mon Sep 17 00:00:00 2001 From: Cosmic Horror Date: Wed, 12 Feb 2025 13:55:27 -0700 Subject: [PATCH] feat: Allow for passing in a customized `reqwest::Client` --- src/blocking.rs | 13 +++++++++---- src/slack.rs | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/blocking.rs b/src/blocking.rs index dabb45ca..6e7a8560 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -12,10 +12,15 @@ pub struct Slack { impl Slack { /// Construct a new instance of slack for a specific incoming url endpoint. pub fn new(hook: T) -> Result { - Ok(Slack { - hook: hook.into_url()?, - client: Client::new(), - }) + Self::new_with_client(hook, Client::new()) + } + + /// The same as [`Slack::new()`], but with a custom [`reqwest::Client`] + /// + /// This allows for configuring custom proxies, DNS resolvers, etc. + pub fn new_with_client(hook: T, client: Client) -> Result { + let hook = hook.into_url()?; + Ok(Self { hook, client }) } /// Send payload to slack service diff --git a/src/slack.rs b/src/slack.rs index d9c4c5e0..50d1f3bd 100644 --- a/src/slack.rs +++ b/src/slack.rs @@ -14,10 +14,15 @@ pub struct Slack { impl Slack { /// Construct a new instance of slack for a specific incoming url endpoint. pub fn new(hook: T) -> Result { - Ok(Slack { - hook: hook.into_url()?, - client: Client::new(), - }) + Self::new_with_client(hook, Client::new()) + } + + /// The same as [`Slack::new()`], but with a custom [`reqwest::Client`] + /// + /// This allows for configuring custom proxies, DNS resolvers, etc. + pub fn new_with_client(hook: T, client: Client) -> Result { + let hook = hook.into_url()?; + Ok(Self { hook, client }) } /// Send payload to slack service