[fractal] backend: use gloable timeout for http request
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] backend: use gloable timeout for http request
- Date: Mon, 18 Feb 2019 09:12:35 +0000 (UTC)
commit 29a87501af0e5cf28fbde858fdc2f76c2b4ce41e
Author: Julian Sparber <julian sparber net>
Date: Sat Feb 2 19:55:02 2019 +0100
backend: use gloable timeout for http request
fractal-matrix-api/src/backend/register.rs | 3 ++-
fractal-matrix-api/src/backend/room.rs | 5 ++---
fractal-matrix-api/src/backend/stickers.rs | 6 ++----
fractal-matrix-api/src/backend/sync.rs | 10 +++-------
fractal-matrix-api/src/backend/user.rs | 4 +---
fractal-matrix-api/src/util.rs | 17 ++++++-----------
6 files changed, 16 insertions(+), 29 deletions(-)
---
diff --git a/fractal-matrix-api/src/backend/register.rs b/fractal-matrix-api/src/backend/register.rs
index d4e465bb..4193957e 100644
--- a/fractal-matrix-api/src/backend/register.rs
+++ b/fractal-matrix-api/src/backend/register.rs
@@ -5,7 +5,6 @@ use std::thread;
use url::Url;
use crate::error::Error;
-use crate::globals;
use crate::util::json_q;
use crate::types::LoginRequest;
@@ -16,6 +15,8 @@ use crate::types::RegisterResponse;
use crate::backend::types::BKResponse;
use crate::backend::types::Backend;
+use crate::globals;
+
pub fn guest(bk: &Backend, server: &str) -> Result<(), Error> {
let baseu = Url::parse(server)?;
let url = baseu
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index 69ced0fb..8699e7bd 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -453,8 +453,7 @@ pub fn set_room_avatar(bk: &Backend, roomid: &str, avatar: &str) -> Result<(), E
&roomurl,
&attrs,
|_| tx.send(BKResponse::SetRoomAvatar).unwrap(),
- |err| tx.send(BKResponse::SetRoomAvatarError(err)).unwrap(),
- 0
+ |err| tx.send(BKResponse::SetRoomAvatarError(err)).unwrap()
);
}
};
@@ -577,7 +576,7 @@ pub fn direct_chat(bk: &Backend, user: &Member, internal_id: String) -> Result<(
}
let attrs = json!(directs.clone());
- put!(&direct_url, &attrs, |_| {}, |err| error!("{:?}", err), 0);
+ put!(&direct_url, &attrs, |_| {}, |err| error!("{:?}", err));
},
|err| {
tx.send(BKResponse::NewRoomError(err, internal_id)).unwrap();
diff --git a/fractal-matrix-api/src/backend/stickers.rs b/fractal-matrix-api/src/backend/stickers.rs
index 30331f3b..0877824b 100644
--- a/fractal-matrix-api/src/backend/stickers.rs
+++ b/fractal-matrix-api/src/backend/stickers.rs
@@ -8,8 +8,6 @@ use std::sync::{Arc, Mutex};
use std::thread;
use url::Url;
-use crate::globals;
-//use std::thread;
use crate::error::Error;
use crate::backend::types::BKCommand;
@@ -187,12 +185,12 @@ fn get_scalar_token(data: &Arc<Mutex<BackendData>>) -> Result<String, Error> {
let uid = data.lock().unwrap().user_id.clone();
let url = url(data, &format!("user/{}/openid/request_token", uid), vec![])?;
- let js = json_q("post", &url, &json!({}), globals::TIMEOUT)?;
+ let js = json_q("post", &url, &json!({}))?;
let vurl = base
.join("/api/register")
.expect("Wrong URL in get_scalar_token()");
- let js = json_q("post", &vurl, &js, globals::TIMEOUT)?;
+ let js = json_q("post", &vurl, &js)?;
match js["scalar_token"].as_str() {
Some(st) => {
diff --git a/fractal-matrix-api/src/backend/sync.rs b/fractal-matrix-api/src/backend/sync.rs
index 02b46d9a..23c8d914 100644
--- a/fractal-matrix-api/src/backend/sync.rs
+++ b/fractal-matrix-api/src/backend/sync.rs
@@ -33,9 +33,7 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) -> Result<()
params.push(("since", since));
}
- let timeout = if !initial {
- time::Duration::from_secs(30)
- } else {
+ if initial {
let filter = Filter {
room: Some(RoomFilter {
state: Some(RoomEventFilter {
@@ -71,10 +69,9 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) -> Result<()
let filter_str =
serde_json::to_string(&filter).expect("Failed to serialize sync request filter");
params.push(("filter", filter_str));
-
- Default::default()
};
+ let timeout = time::Duration::from_secs(30);
params.push(("timeout", timeout.as_secs().to_string()));
let baseu = bk.get_base_url();
@@ -192,8 +189,7 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) -> Result<()
thread::sleep(time::Duration::from_secs(10));
tx.send(BKResponse::SyncError(err)).unwrap();
- },
- timeout.as_secs()
+ }
);
Ok(())
diff --git a/fractal-matrix-api/src/backend/user.rs b/fractal-matrix-api/src/backend/user.rs
index 4d95ad57..293aa2bc 100644
--- a/fractal-matrix-api/src/backend/user.rs
+++ b/fractal-matrix-api/src/backend/user.rs
@@ -6,7 +6,6 @@ use std::io::prelude::*;
use crate::backend::types::BKResponse;
use crate::backend::types::Backend;
use crate::error::Error;
-use crate::globals;
use crate::util::encode_uid;
use crate::util::get_user_avatar;
use crate::util::get_user_avatar_img;
@@ -496,8 +495,7 @@ pub fn set_user_avatar(bk: &Backend, avatar: String) -> Result<(), Error> {
&url,
&attrs,
|_| tx.send(BKResponse::SetUserAvatar(avatar)).unwrap(),
- |err| tx.send(BKResponse::SetUserAvatarError(err)).unwrap(),
- 0
+ |err| tx.send(BKResponse::SetUserAvatarError(err)).unwrap()
);
}
};
diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs
index 05fad2ee..1d9f9bef 100644
--- a/fractal-matrix-api/src/util.rs
+++ b/fractal-matrix-api/src/util.rs
@@ -127,9 +127,9 @@ macro_rules! put {
#[macro_export]
macro_rules! query {
- ($method: expr, $url: expr, $attrs: expr, $okcb: expr, $errcb: expr, $timeout: expr) => {
+ ($method: expr, $url: expr, $attrs: expr, $okcb: expr, $errcb: expr) => {
thread::spawn(move || {
- let js = json_q($method, $url, $attrs, $timeout);
+ let js = json_q($method, $url, $attrs);
match js {
Ok(r) => $okcb(r),
@@ -177,7 +177,7 @@ pub fn get_prev_batch_from(
let path = format!("rooms/{}/context/{}", roomid, evid);
let url = client_url(baseu, &path, params)?;
- let r = json_q("get", &url, &json!(null), globals::TIMEOUT)?;
+ let r = json_q("get", &url, &json!(null))?;
let prev_batch = r["start"].to_string().trim_matches('"').to_string();
Ok(prev_batch)
@@ -218,7 +218,7 @@ pub fn get_room_media_list(
let path = format!("rooms/{}/messages", roomid);
let url = client_url(baseu, &path, ¶ms)?;
- let r = json_q("get", &url, &json!(null), globals::TIMEOUT)?;
+ let r = json_q("get", &url, &json!(null))?;
let array = r["chunk"].as_array();
let prev_batch = r["end"].to_string().trim_matches('"').to_string();
if array.is_none() || array.unwrap().is_empty() {
@@ -348,12 +348,7 @@ pub fn download_file(url: &str, fname: String, dest: Option<&str>) -> Result<Str
Ok(fname)
}
-pub fn json_q(
- method: &str,
- url: &Url,
- attrs: &JsonValue,
- _timeout: u64,
-) -> Result<JsonValue, Error> {
+pub fn json_q(method: &str, url: &Url, attrs: &JsonValue) -> Result<JsonValue, Error> {
let mut conn = match method {
"post" => HTTP_CLIENT.post(url.as_str()),
"put" => HTTP_CLIENT.put(url.as_str()),
@@ -398,7 +393,7 @@ pub fn get_user_avatar(baseu: &Url, userid: &str) -> Result<(String, String), Er
let url = client_url(baseu, &format!("profile/{}", encode_uid(userid)), &[])?;
let attrs = json!(null);
- match json_q("get", &url, &attrs, globals::TIMEOUT) {
+ match json_q("get", &url, &attrs) {
Ok(js) => {
let name = match js["displayname"].as_str() {
Some(n) if n.is_empty() => userid.to_string(),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]