mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
Add timeouts to HTTP requests (#3908)
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
- fix: only send contact changed event for recently seen if it is relevant (not too old to matter) #3938
|
- fix: only send contact changed event for recently seen if it is relevant (not too old to matter) #3938
|
||||||
- Immediately save `accounts.toml` if it was modified by a migration from absolute paths to relative paths #3943
|
- Immediately save `accounts.toml` if it was modified by a migration from absolute paths to relative paths #3943
|
||||||
- Do not treat invalid email addresses as an exception #3942
|
- Do not treat invalid email addresses as an exception #3942
|
||||||
|
- Add timeouts to HTTP requests #3948
|
||||||
|
|
||||||
|
|
||||||
## 1.105.0
|
## 1.105.0
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub async fn read_url(context: &Context, url: &str) -> anyhow::Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_url_inner(context: &Context, url: &str) -> anyhow::Result<String> {
|
pub async fn read_url_inner(context: &Context, url: &str) -> anyhow::Result<String> {
|
||||||
let client = reqwest::Client::new();
|
let client = crate::http::get_client()?;
|
||||||
let mut url = url.to_string();
|
let mut url = url.to_string();
|
||||||
|
|
||||||
// Follow up to 10 http-redirects
|
// Follow up to 10 http-redirects
|
||||||
|
|||||||
12
src/http.rs
Normal file
12
src/http.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
//! # HTTP module.
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
const HTTP_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
|
pub(crate) fn get_client() -> Result<reqwest::Client> {
|
||||||
|
Ok(reqwest::ClientBuilder::new()
|
||||||
|
.timeout(HTTP_TIMEOUT)
|
||||||
|
.build()?)
|
||||||
|
}
|
||||||
@@ -66,6 +66,7 @@ mod decrypt;
|
|||||||
pub mod download;
|
pub mod download;
|
||||||
mod e2ee;
|
mod e2ee;
|
||||||
pub mod ephemeral;
|
pub mod ephemeral;
|
||||||
|
mod http;
|
||||||
mod imap;
|
mod imap;
|
||||||
pub mod imex;
|
pub mod imex;
|
||||||
mod scheduler;
|
mod scheduler;
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ pub async fn get_oauth2_access_token(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ... and POST
|
// ... and POST
|
||||||
let client = reqwest::Client::new();
|
let client = crate::http::get_client()?;
|
||||||
|
|
||||||
let response: Response = match client.post(post_url).form(&post_param).send().await {
|
let response: Response = match client.post(post_url).form(&post_param).send().await {
|
||||||
Ok(resp) => match resp.json().await {
|
Ok(resp) => match resp.json().await {
|
||||||
@@ -284,7 +284,14 @@ impl Oauth2 {
|
|||||||
// "verified_email": true,
|
// "verified_email": true,
|
||||||
// "picture": "https://lh4.googleusercontent.com/-Gj5jh_9R0BY/AAAAAAAAAAI/AAAAAAAAAAA/IAjtjfjtjNA/photo.jpg"
|
// "picture": "https://lh4.googleusercontent.com/-Gj5jh_9R0BY/AAAAAAAAAAI/AAAAAAAAAAA/IAjtjfjtjNA/photo.jpg"
|
||||||
// }
|
// }
|
||||||
let response = match reqwest::get(userinfo_url).await {
|
let client = match crate::http::get_client() {
|
||||||
|
Ok(cl) => cl,
|
||||||
|
Err(err) => {
|
||||||
|
warn!(context, "failed to get HTTP client: {}", err);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let response = match client.get(userinfo_url).send().await {
|
||||||
Ok(response) => response,
|
Ok(response) => response,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(context, "failed to get userinfo: {}", err);
|
warn!(context, "failed to get userinfo: {}", err);
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ struct CreateAccountErrorResponse {
|
|||||||
#[allow(clippy::indexing_slicing)]
|
#[allow(clippy::indexing_slicing)]
|
||||||
async fn set_account_from_qr(context: &Context, qr: &str) -> Result<()> {
|
async fn set_account_from_qr(context: &Context, qr: &str) -> Result<()> {
|
||||||
let url_str = &qr[DCACCOUNT_SCHEME.len()..];
|
let url_str = &qr[DCACCOUNT_SCHEME.len()..];
|
||||||
let response = reqwest::Client::new().post(url_str).send().await?;
|
let response = crate::http::get_client()?.post(url_str).send().await?;
|
||||||
let response_status = response.status();
|
let response_status = response.status();
|
||||||
let response_text = response.text().await.with_context(|| {
|
let response_text = response.text().await.with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
|
|||||||
Reference in New Issue
Block a user