mirror of https://github.com/LemmyNet/lemmy.git
Also set request timeouts in utils/src/request.rs
parent
c416efdc0d
commit
fccb055232
|
@ -4,7 +4,7 @@ use encoding::{all::encodings, DecoderTrap};
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::future::Future;
|
use std::{future::Future, time::Duration};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -69,7 +69,11 @@ pub async fn fetch_site_metadata(
|
||||||
url: &Url,
|
url: &Url,
|
||||||
) -> Result<SiteMetadata, LemmyError> {
|
) -> Result<SiteMetadata, LemmyError> {
|
||||||
info!("Fetching site metadata for url: {}", url);
|
info!("Fetching site metadata for url: {}", url);
|
||||||
let response = client.get(url.as_str()).send().await?;
|
let response = client
|
||||||
|
.get(url.as_str())
|
||||||
|
.timeout(Duration::from_secs(30))
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Can't use .text() here, because it only checks the content header, not the actual bytes
|
// Can't use .text() here, because it only checks the content header, not the actual bytes
|
||||||
// https://github.com/LemmyNet/lemmy/issues/1964
|
// https://github.com/LemmyNet/lemmy/issues/1964
|
||||||
|
@ -177,7 +181,11 @@ pub(crate) async fn fetch_pictrs(
|
||||||
utf8_percent_encode(image_url.as_str(), NON_ALPHANUMERIC) // TODO this might not be needed
|
utf8_percent_encode(image_url.as_str(), NON_ALPHANUMERIC) // TODO this might not be needed
|
||||||
);
|
);
|
||||||
|
|
||||||
let response = client.get(&fetch_url).send().await?;
|
let response = client
|
||||||
|
.get(&fetch_url)
|
||||||
|
.timeout(Duration::from_secs(30))
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
let response: PictrsResponse = response
|
let response: PictrsResponse = response
|
||||||
.json()
|
.json()
|
||||||
|
@ -249,7 +257,11 @@ pub async fn fetch_site_data(
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> {
|
async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> {
|
||||||
let response = client.get(url.as_str()).send().await?;
|
let response = client
|
||||||
|
.get(url.as_str())
|
||||||
|
.timeout(Duration::from_secs(30))
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
if response
|
if response
|
||||||
.headers()
|
.headers()
|
||||||
.get("Content-Type")
|
.get("Content-Type")
|
||||||
|
|
Loading…
Reference in New Issue