Timeout after 20 seconds (#3054)

This commit is contained in:
Quentin Le Sceller
2019-09-24 04:57:59 -04:00
committed by Antioch Peverell
parent 973a03c826
commit 84172216a5
3 changed files with 45 additions and 1 deletions
+7 -1
View File
@@ -23,8 +23,10 @@ use hyper::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE, USER_AGENT};
use hyper::rt::{Future, Stream};
use hyper::{Body, Client, Request};
use hyper_rustls;
use hyper_timeout::TimeoutConnector;
use serde::{Deserialize, Serialize};
use serde_json;
use std::time::Duration;
use tokio::runtime::Runtime;
pub type ClientResponseFuture<T> = Box<dyn Future<Item = T, Error = Error> + Send>;
@@ -195,7 +197,11 @@ where
fn send_request_async(req: Request<Body>) -> Box<dyn Future<Item = String, Error = Error> + Send> {
let https = hyper_rustls::HttpsConnector::new(1);
let client = Client::builder().build::<_, Body>(https);
let mut connector = TimeoutConnector::new(https);
connector.set_connect_timeout(Some(Duration::from_secs(20)));
connector.set_read_timeout(Some(Duration::from_secs(20)));
connector.set_write_timeout(Some(Duration::from_secs(20)));
let client = Client::builder().build::<_, hyper::Body>(connector);
Box::new(
client
.request(req)