From df117f855bb9f70f7f2318fd8e8e6441c7255529 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 26 Feb 2019 17:54:47 +0100 Subject: [PATCH] feat: Add `Request::timeout` method --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9366a2c3d..ea3a7f8ba 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.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 {