summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-10-15 17:47:17 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-10-15 17:47:17 -0500
commitabda1529e4bfafa9255e6460353d218bd3c048e3 (patch)
treeda875f586dc20fbaf366d8407a2855c460fb14c3 /src
parente5c1b2efb597bc7089e833bf570d8217c36f50c3 (diff)
fix(http): use LazyLock for reqwest::ClientHEADv0.1.1main
Diffstat (limited to 'src')
-rw-r--r--src/service/http.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/service/http.rs b/src/service/http.rs
index 5b0fdd5..ce9a7e4 100644
--- a/src/service/http.rs
+++ b/src/service/http.rs
@@ -1,7 +1,6 @@
-use std::{fmt::Display, time::Duration};
+use std::{fmt::Display, sync::LazyLock, time::Duration};
use axum::http::status::StatusCode;
-use reqwest::Client;
use serde::{Deserialize, Serialize};
use url::Url;
@@ -9,6 +8,8 @@ use crate::status::Sender;
use super::IntoService;
+static CLIENT: LazyLock<reqwest::Client> = LazyLock::new(reqwest::Client::new);
+
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Request error: {0}")]
@@ -24,18 +25,13 @@ pub struct Http {
pub method: Method,
#[serde(default, with = "status_code")]
pub status_code: StatusCode,
- #[serde(skip, default)]
- pub client: Option<reqwest::Client>,
#[serde(default = "super::default_interval")]
pub interval: Duration,
}
impl Http {
async fn check(&self) -> Result<(), Error> {
- let client = match self.client.as_ref() {
- Some(client) => client,
- None => &Client::new(),
- };
+ let client = CLIENT.clone();
let req = client
.request(self.method.into(), self.url.clone())
.build()?;