Return Err on deadline checked_add overflow instead of panic (#517)

This commit is contained in:
guyo13
2022-05-22 20:51:58 +03:00
committed by GitHub
parent 8a32cae507
commit c94284482a

View File

@@ -3,12 +3,13 @@ use std::{fmt, time};
use url::{form_urlencoded, ParseError, Url};
use crate::agent::Agent;
use crate::body::Payload;
use crate::error::{Error, ErrorKind};
use crate::header::{self, Header};
use crate::middleware::MiddlewareNext;
use crate::unit::{self, Unit};
use crate::Response;
use crate::{agent::Agent, error::Error};
pub type Result<T> = std::result::Result<T, Error>;
@@ -123,7 +124,15 @@ impl Request {
None => None,
Some(timeout) => {
let now = time::Instant::now();
Some(now.checked_add(timeout).unwrap())
match now.checked_add(timeout) {
Some(dl) => Some(dl),
None => {
return Err(Error::new(
ErrorKind::Io,
Some("Request deadline overflowed".to_string()),
))
}
}
}
};