about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-26T16·55+0100
committerVincent Ambo <mail@tazj.in>2019-02-26T16·55+0100
commitcf58060fccb68088b1a9f82f484f1f8b635fa61e (patch)
treedb1442b71370f3a018c96a1fc7844e5ffa794073 /src
parentdf117f855bb9f70f7f2318fd8e8e6441c7255529 (diff)
feat: Add `Request::with_handle` method
This method acts as an "escape-hatch" which lets the user configure
whatever they want on the cURL easy handle. No warranty!
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ea3a7f8ba2b5..978f21c6ad24 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -228,6 +228,27 @@ impl <'a> Request<'a> {
         Ok(self)
     }
 
+    /// Set custom configuration on the cURL `Easy` handle.
+    ///
+    /// This function can be considered an "escape-hatch" from the
+    /// high-level API which lets users access the internal
+    /// `curl::easy::Easy` handle and configure options on it
+    /// directly.
+    ///
+    /// ```
+    /// # use crimp::{Request, Method};
+    /// let response = Request::new(Method::Get, "https://httpbin.org/get")
+    ///     .with_handle(|mut handle| handle.referer("Example-Referer")).unwrap()
+    ///     .send().unwrap();
+    /// #
+    /// # assert!(response.is_success());
+    /// ```
+    pub fn with_handle<F>(mut self, function: F) -> Result<Self, curl::Error>
+    where F: FnOnce(&mut Easy) -> Result<(), curl::Error> {
+        function(&mut self.handle)?;
+        Ok(self)
+    }
+
     /// Add a byte-array body to a request using the specified
     /// `Content-Type`.
     pub fn body(mut self, content_type: &'a str, data: &'a [u8]) -> Self {