fix: extern controler api secert with headers

This commit is contained in:
Tunglies
2025-03-05 07:59:16 +08:00
parent f771f4720f
commit b01630d31c
3 changed files with 12 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
use reqwest::header::HeaderMap;
use std::{
sync::{Arc, Mutex},
time::Duration,
@@ -6,13 +7,14 @@ pub mod model;
pub use model::{MihomoData, MihomoManager};
impl MihomoManager {
pub fn new(mihomo_server: String) -> Self {
pub fn new(mihomo_server: String, headers: HeaderMap) -> Self {
Self {
mihomo_server,
data: Arc::new(Mutex::new(MihomoData {
proxies: serde_json::Value::Null,
providers_proxies: serde_json::Value::Null,
})),
headers: headers,
}
}
@@ -39,6 +41,7 @@ impl MihomoManager {
pub async fn refresh_proxies(&self) -> Result<&Self, String> {
let url = format!("{}/proxies", self.mihomo_server);
let response = reqwest::ClientBuilder::new()
.default_headers(self.headers.clone())
.no_proxy()
.timeout(Duration::from_secs(3))
.build()
@@ -58,6 +61,7 @@ impl MihomoManager {
pub async fn refresh_providers_proxies(&self) -> Result<&Self, String> {
let url = format!("{}/providers/proxies", self.mihomo_server);
let response = reqwest::ClientBuilder::new()
.default_headers(self.headers.clone())
.no_proxy()
.timeout(Duration::from_secs(3))
.build()

View File

@@ -1,4 +1,5 @@
use std::sync::{Arc, Mutex};
use reqwest::header::HeaderMap;
pub struct MihomoData {
pub(crate) proxies: serde_json::Value,
@@ -9,6 +10,7 @@ pub struct MihomoData {
pub struct MihomoManager {
pub(crate) mihomo_server: String,
pub(crate) data: Arc<Mutex<MihomoData>>,
pub(crate) headers: HeaderMap,
}
#[cfg(feature = "debug")]