reduce reqwest timeout to 5s (#557)

This commit is contained in:
fdb-hiroshima 2019-04-30 23:30:13 +02:00 committed by GitHub
parent 8f1ab3485e
commit 33a0c7dcd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 16 deletions

View File

@ -279,7 +279,10 @@ pub trait FromId<C>: Sized {
/// Dereferences an ID /// Dereferences an ID
fn deref(id: &str) -> Result<Self::Object, (Option<serde_json::Value>, Self::Error)> { fn deref(id: &str) -> Result<Self::Object, (Option<serde_json::Value>, Self::Error)> {
reqwest::Client::new() reqwest::ClientBuilder::new()
.connect_timeout(Some(std::time::Duration::from_secs(5)))
.build()
.map_err(|_| (None, InboxError::DerefError.into()))?
.get(id) .get(id)
.header( .header(
ACCEPT, ACCEPT,

View File

@ -1,6 +1,6 @@
use activitypub::{Activity, Link, Object}; use activitypub::{Activity, Link, Object};
use array_tool::vec::Uniq; use array_tool::vec::Uniq;
use reqwest::Client; use reqwest::ClientBuilder;
use rocket::{ use rocket::{
http::Status, http::Status,
request::{FromRequest, Request}, request::{FromRequest, Request},
@ -134,16 +134,21 @@ where
let body = signed.to_string(); let body = signed.to_string();
let mut headers = request::headers(); let mut headers = request::headers();
headers.insert("Digest", request::Digest::digest(&body)); headers.insert("Digest", request::Digest::digest(&body));
let res = Client::new() let res = ClientBuilder::new()
.post(&inbox) .connect_timeout(Some(std::time::Duration::from_secs(5)))
.headers(headers.clone()) .build()
.header( .and_then(|client| {
"Signature", client
request::signature(sender, &headers) .post(&inbox)
.expect("activity_pub::broadcast: request signature error"), .headers(headers.clone())
) .header(
.body(body) "Signature",
.send(); request::signature(sender, &headers)
.expect("activity_pub::broadcast: request signature error"),
)
.body(body)
.send()
});
match res { match res {
Ok(mut r) => { Ok(mut r) => {
println!("Successfully sent activity to inbox ({})", inbox); println!("Successfully sent activity to inbox ({})", inbox);

View File

@ -23,7 +23,7 @@ use plume_common::activity_pub::{
use plume_common::utils; use plume_common::utils;
use reqwest::{ use reqwest::{
header::{HeaderValue, ACCEPT}, header::{HeaderValue, ACCEPT},
Client, ClientBuilder,
}; };
use rocket::{ use rocket::{
outcome::IntoOutcome, outcome::IntoOutcome,
@ -267,7 +267,9 @@ impl User {
} }
fn fetch(url: &str) -> Result<CustomPerson> { fn fetch(url: &str) -> Result<CustomPerson> {
let mut res = Client::new() let mut res = ClientBuilder::new()
.connect_timeout(Some(std::time::Duration::from_secs(5)))
.build()?
.get(url) .get(url)
.header( .header(
ACCEPT, ACCEPT,
@ -369,7 +371,9 @@ impl User {
} }
pub fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> { pub fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> {
let mut res = Client::new() let mut res = ClientBuilder::new()
.connect_timeout(Some(std::time::Duration::from_secs(5)))
.build()?
.get(&self.outbox_url[..]) .get(&self.outbox_url[..])
.header( .header(
ACCEPT, ACCEPT,
@ -392,7 +396,9 @@ impl User {
} }
pub fn fetch_followers_ids(&self) -> Result<Vec<String>> { pub fn fetch_followers_ids(&self) -> Result<Vec<String>> {
let mut res = Client::new() let mut res = ClientBuilder::new()
.connect_timeout(Some(std::time::Duration::from_secs(5)))
.build()?
.get(&self.followers_endpoint[..]) .get(&self.followers_endpoint[..])
.header( .header(
ACCEPT, ACCEPT,