about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-26T16·54+0100
committerVincent Ambo <mail@tazj.in>2019-02-26T16·54+0100
commitdf117f855bb9f70f7f2318fd8e8e6441c7255529 (patch)
tree2ced60a0659138d29292403e3596e6ea93ff5d7b
parentacc7e64a0d0d26ad2c529b992b96b72f8029d29d (diff)
feat: Add `Request::timeout` method
-rw-r--r--src/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9366a2c3d087..ea3a7f8ba2b5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -73,6 +73,7 @@ use std::collections::HashMap;
 use std::io::Write;
 use std::path::Path;
 use std::string::{FromUtf8Error, ToString};
+use std::time::Duration;
 
 #[cfg(feature = "json")] use serde::Serialize;
 #[cfg(feature = "json")] use serde::de::DeserializeOwned;
@@ -220,6 +221,13 @@ impl <'a> Request<'a> {
         Ok(self)
     }
 
+    /// Configure a timeout for the request after which the request
+    /// will be aborted.
+    pub fn timeout(mut self, timeout: Duration) -> Result<Self, curl::Error> {
+        self.handle.timeout(timeout)?;
+        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 {