From 97ee9cfb3354f52e4ee3ffaede327be5c2364615 Mon Sep 17 00:00:00 2001
From: swanandx <73115739+swanandx@users.noreply.github.com>
Date: Fri, 15 Dec 2023 19:11:54 +0530
Subject: [PATCH 1/4] fix: update request modifier fn type to impl send and
 sync

---
 rumqttc/src/v5/mod.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/rumqttc/src/v5/mod.rs b/rumqttc/src/v5/mod.rs
index a7c1c636d..2af0125cf 100644
--- a/rumqttc/src/v5/mod.rs
+++ b/rumqttc/src/v5/mod.rs
@@ -50,8 +50,9 @@ pub enum Request {
 }
 
 #[cfg(feature = "websocket")]
-type RequestModifierFn =
-    dyn Fn(http::Request<()>) -> Pin<Box<dyn Future<Output = http::Request<()>>>>;
+type RequestModifierFn = (dyn Fn(http::Request<()>) -> Pin<Box<dyn Future<Output = http::Request<()>> + Send>>
+     + Send
+     + Sync);
 
 // TODO: Should all the options be exposed as public? Drawback
 // would be loosing the ability to panic when the user options
@@ -201,8 +202,9 @@ impl MqttOptions {
     #[cfg(feature = "websocket")]
     pub fn set_request_modifier<F, O>(&mut self, request_modifier: F) -> &mut Self
     where
-        F: Fn(http::Request<()>) -> O + 'static,
+        F: Fn(http::Request<()>) -> O + Sync + Send + 'static,
         O: IntoFuture<Output = http::Request<()>>,
+        <O as IntoFuture>::IntoFuture: Send,
     {
         let request_modifier = Arc::new(Box::new(request_modifier));
         self.request_modifier = Some(Arc::new(Box::new(move |request| {

From 77661e03cee4cc3745910a358bd3609ba02747d1 Mon Sep 17 00:00:00 2001
From: swanandx <73115739+swanandx@users.noreply.github.com>
Date: Fri, 15 Dec 2023 19:16:12 +0530
Subject: [PATCH 2/4] chore: update changelog entry

---
 rumqttc/CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rumqttc/CHANGELOG.md b/rumqttc/CHANGELOG.md
index 842aed732..756dda353 100644
--- a/rumqttc/CHANGELOG.md
+++ b/rumqttc/CHANGELOG.md
@@ -25,6 +25,7 @@ To update your code simply remove `Key::ECC()` or `Key::RSA()` from the initiali
 
 ### Fixed
 - Lowered the MSRV to 1.64.0
+- Request modifier function should be Send and Sync
 
 ### Security
 

From 24972d9be4a1c027d334898d5fef82bc75e32848 Mon Sep 17 00:00:00 2001
From: swanandx <73115739+swanandx@users.noreply.github.com>
Date: Fri, 15 Dec 2023 23:53:17 +0530
Subject: [PATCH 3/4] feat: removed unnecessary box

---
 rumqttc/CHANGELOG.md  |  2 +-
 rumqttc/src/v5/mod.rs | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/rumqttc/CHANGELOG.md b/rumqttc/CHANGELOG.md
index 756dda353..0c8b65382 100644
--- a/rumqttc/CHANGELOG.md
+++ b/rumqttc/CHANGELOG.md
@@ -25,7 +25,7 @@ To update your code simply remove `Key::ECC()` or `Key::RSA()` from the initiali
 
 ### Fixed
 - Lowered the MSRV to 1.64.0
-- Request modifier function should be Send and Sync
+- Request modifier function should be Send and Sync and removed unnecessary Box
 
 ### Security
 
diff --git a/rumqttc/src/v5/mod.rs b/rumqttc/src/v5/mod.rs
index 2af0125cf..74e9ef36d 100644
--- a/rumqttc/src/v5/mod.rs
+++ b/rumqttc/src/v5/mod.rs
@@ -101,7 +101,7 @@ pub struct MqttOptions {
     /// The server may set its own maximum inflight limit, the smaller of the two will be used.
     outgoing_inflight_upper_limit: Option<u16>,
     #[cfg(feature = "websocket")]
-    request_modifier: Option<Arc<Box<RequestModifierFn>>>,
+    request_modifier: Option<Arc<RequestModifierFn>>,
 }
 
 impl MqttOptions {
@@ -206,18 +206,18 @@ impl MqttOptions {
         O: IntoFuture<Output = http::Request<()>>,
         <O as IntoFuture>::IntoFuture: Send,
     {
-        let request_modifier = Arc::new(Box::new(request_modifier));
-        self.request_modifier = Some(Arc::new(Box::new(move |request| {
+        let request_modifier = Arc::new(request_modifier);
+        self.request_modifier = Some(Arc::new(move |request| {
             Box::pin({
                 let request_modifier = Arc::clone(&request_modifier);
                 async move { request_modifier(request).into_future().await }
             })
-        })));
+        }));
         self
     }
 
     #[cfg(feature = "websocket")]
-    pub fn request_modifier(&self) -> Option<Arc<Box<RequestModifierFn>>> {
+    pub fn request_modifier(&self) -> Option<Arc<RequestModifierFn>> {
         self.request_modifier.clone()
     }
 

From 32146aa92f17378faa6e49c25a06a71109c8fe8a Mon Sep 17 00:00:00 2001
From: swanandx <73115739+swanandx@users.noreply.github.com>
Date: Sun, 17 Dec 2023 15:22:47 +0530
Subject: [PATCH 4/4] feat: commit changes asked in review

---
 rumqttc/src/v5/mod.rs | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/rumqttc/src/v5/mod.rs b/rumqttc/src/v5/mod.rs
index 74e9ef36d..4b6793b03 100644
--- a/rumqttc/src/v5/mod.rs
+++ b/rumqttc/src/v5/mod.rs
@@ -50,9 +50,11 @@ pub enum Request {
 }
 
 #[cfg(feature = "websocket")]
-type RequestModifierFn = (dyn Fn(http::Request<()>) -> Pin<Box<dyn Future<Output = http::Request<()>> + Send>>
-     + Send
-     + Sync);
+type RequestModifierFn = Arc<
+    dyn Fn(http::Request<()>) -> Pin<Box<dyn Future<Output = http::Request<()>> + Send>>
+        + Send
+        + Sync,
+>;
 
 // TODO: Should all the options be exposed as public? Drawback
 // would be loosing the ability to panic when the user options
@@ -101,7 +103,7 @@ pub struct MqttOptions {
     /// The server may set its own maximum inflight limit, the smaller of the two will be used.
     outgoing_inflight_upper_limit: Option<u16>,
     #[cfg(feature = "websocket")]
-    request_modifier: Option<Arc<RequestModifierFn>>,
+    request_modifier: Option<RequestModifierFn>,
 }
 
 impl MqttOptions {
@@ -202,22 +204,20 @@ impl MqttOptions {
     #[cfg(feature = "websocket")]
     pub fn set_request_modifier<F, O>(&mut self, request_modifier: F) -> &mut Self
     where
-        F: Fn(http::Request<()>) -> O + Sync + Send + 'static,
-        O: IntoFuture<Output = http::Request<()>>,
-        <O as IntoFuture>::IntoFuture: Send,
+        F: Fn(http::Request<()>) -> O + Send + Sync + 'static,
+        O: IntoFuture<Output = http::Request<()>> + 'static,
+        O::IntoFuture: Send,
     {
-        let request_modifier = Arc::new(request_modifier);
         self.request_modifier = Some(Arc::new(move |request| {
-            Box::pin({
-                let request_modifier = Arc::clone(&request_modifier);
-                async move { request_modifier(request).into_future().await }
-            })
+            let request_modifier = request_modifier(request).into_future();
+            Box::pin(request_modifier)
         }));
+
         self
     }
 
     #[cfg(feature = "websocket")]
-    pub fn request_modifier(&self) -> Option<Arc<RequestModifierFn>> {
+    pub fn request_modifier(&self) -> Option<RequestModifierFn> {
         self.request_modifier.clone()
     }