Reinstate read timeouts on body.

This feature was broken in #67, which reset timeouts on the
stream before passing it to set_stream.

As part of this change, refactor the internal storage of
timeouts on the Request object to use Option<Duration>.

Remove the deadline field on Response. It wasn't used. The
deadline field on unit was used instead.

Add a unittest.
This commit is contained in:
Jacob Hoffman-Andrews
2020-10-21 20:39:34 -07:00
committed by Martin Algesten
parent 32f9ebc04a
commit 2bf9362eff
4 changed files with 56 additions and 24 deletions

View File

@@ -1,8 +1,8 @@
use std::fmt;
use std::io::Read;
use std::result::Result;
use std::sync::{Arc, Mutex};
use std::time;
use std::{fmt, time::Duration};
use qstring::QString;
use url::{form_urlencoded, Url};
@@ -40,8 +40,8 @@ pub struct Request {
pub(crate) headers: Vec<Header>,
pub(crate) query: QString,
pub(crate) timeout_connect: u64,
pub(crate) timeout_read: u64,
pub(crate) timeout_write: u64,
pub(crate) timeout_read: Option<time::Duration>,
pub(crate) timeout_write: Option<time::Duration>,
pub(crate) timeout: Option<time::Duration>,
pub(crate) redirects: u32,
pub(crate) proxy: Option<Proxy>,
@@ -368,7 +368,10 @@ impl Request {
/// println!("{:?}", r);
/// ```
pub fn timeout_read(&mut self, millis: u64) -> &mut Request {
self.timeout_read = millis;
match millis {
0 => self.timeout_read = None,
m => self.timeout_read = Some(Duration::from_millis(m)),
}
self
}
@@ -385,7 +388,10 @@ impl Request {
/// println!("{:?}", r);
/// ```
pub fn timeout_write(&mut self, millis: u64) -> &mut Request {
self.timeout_write = millis;
match millis {
0 => self.timeout_write = None,
m => self.timeout_write = Some(Duration::from_millis(m)),
}
self
}