mirror of
https://github.com/sadoyan/aralez.git
synced 2026-10-23 06:01:35 +08:00
Minor improvements, type changes
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use crate::utils::hcclient::{httpclient, HttpClientRequest};
|
||||
use crate::utils::hcclient::{HttpClientRequest, httpclient};
|
||||
use crate::utils::lazylock::REVERSE_STORE;
|
||||
use crate::utils::tools::*;
|
||||
use crate::utils::types::{InnerMap, UpstreamsDashMap, UpstreamsIdMap};
|
||||
use bytes::Bytes;
|
||||
use dashmap::DashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::time::Duration;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::time::{interval, timeout};
|
||||
@@ -44,7 +44,7 @@ async fn build_upstreams(fullist: &UpstreamsDashMap, method: &str) -> UpstreamsD
|
||||
let mut innervec = Vec::new();
|
||||
|
||||
for upstream in path_entry.value().0.iter() {
|
||||
let tls = if upstream.healthcheck.unwrap_or(true) {
|
||||
let tls = if upstream.healthcheck {
|
||||
detect_tls(upstream.address.as_ref(), &upstream.port, host).await
|
||||
} else {
|
||||
false
|
||||
@@ -62,7 +62,7 @@ async fn build_upstreams(fullist: &UpstreamsDashMap, method: &str) -> UpstreamsD
|
||||
authorization: upstream.authorization.clone(),
|
||||
};
|
||||
|
||||
if scheme.healthcheck.unwrap_or(true) {
|
||||
if scheme.healthcheck {
|
||||
let link = if tls {
|
||||
format!("https://{}:{}{}", upstream.address, upstream.port, path)
|
||||
} else {
|
||||
|
||||
+7
-11
@@ -90,10 +90,10 @@ pub async fn for_consul(url: &str, token: Option<String>, conf: &GlobalServiceMa
|
||||
is_ssl: false,
|
||||
is_http2: false,
|
||||
to_https: conf.to_https.unwrap_or(false),
|
||||
rate_limit: conf.rate_limit,
|
||||
x4xx_limit: conf.x4xx_limit,
|
||||
rate_limit: conf.rate_limit.unwrap_or(0),
|
||||
x4xx_limit: conf.x4xx_limit.unwrap_or(0),
|
||||
redirect_to: conf.redirect_to.clone().map(Arc::<str>::from),
|
||||
healthcheck: None,
|
||||
healthcheck: true,
|
||||
authorization: None,
|
||||
});
|
||||
inner_vec.push(to_add);
|
||||
@@ -132,9 +132,9 @@ pub async fn for_kuber(url: &str, token: &str, conf: &GlobalServiceMapping) -> O
|
||||
is_ssl: false,
|
||||
is_http2: false,
|
||||
to_https: conf.to_https.unwrap_or(false),
|
||||
rate_limit: conf.rate_limit,
|
||||
x4xx_limit: conf.x4xx_limit,
|
||||
healthcheck: None,
|
||||
rate_limit: conf.rate_limit.unwrap_or(0),
|
||||
x4xx_limit: conf.x4xx_limit.unwrap_or(0),
|
||||
healthcheck: true,
|
||||
redirect_to: None,
|
||||
authorization: None,
|
||||
});
|
||||
@@ -213,11 +213,7 @@ pub async fn getfromapi(url: &str, token: Option<String>, provider: &str) -> Opt
|
||||
|
||||
CONNECTOR.release_http_session(http_session.0, &peer, None).await;
|
||||
|
||||
if status == 200 && !body_bytes.is_empty() {
|
||||
Some(body_bytes)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if status == 200 && !body_bytes.is_empty() { Some(body_bytes) } else { None }
|
||||
}
|
||||
|
||||
fn parse_url(url: &str) -> Result<(&str, u16, &str, bool), &'static str> {
|
||||
|
||||
@@ -172,10 +172,10 @@ async fn populate_headers_and_auth(config: &mut Configuration, parsed: &Config)
|
||||
let server_global_headers: DashMap<Arc<str>, Vec<(String, Arc<str>)>> = DashMap::new();
|
||||
server_global_headers.insert(Arc::from("/"), sh);
|
||||
config.server_headers.insert(Arc::from("GLOBAL_SERVER_HEADERS"), server_global_headers);
|
||||
config.extraparams.to_https = parsed.to_https;
|
||||
config.extraparams.sticky_sessions = parsed.sticky_sessions;
|
||||
config.extraparams.rate_limit = parsed.rate_limit;
|
||||
config.extraparams.x4xx_limit = parsed.x4xx_limit;
|
||||
config.extraparams.to_https = parsed.to_https.unwrap_or(false);
|
||||
config.extraparams.sticky_sessions = parsed.sticky_sessions.unwrap_or(0);
|
||||
config.extraparams.rate_limit = parsed.rate_limit.unwrap_or(0);
|
||||
config.extraparams.x4xx_limit = parsed.x4xx_limit.unwrap_or(0);
|
||||
|
||||
if let Some(rate) = &parsed.rate_limit {
|
||||
info!("Applied Global Rate Limit : {} request per second", rate);
|
||||
@@ -228,9 +228,9 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) {
|
||||
is_ssl: false,
|
||||
is_http2: false,
|
||||
to_https: path_config.to_https.unwrap_or(false),
|
||||
rate_limit: path_config.rate_limit,
|
||||
x4xx_limit: path_config.x4xx_limit,
|
||||
healthcheck: path_config.healthcheck,
|
||||
rate_limit: path_config.rate_limit.unwrap_or(0),
|
||||
x4xx_limit: path_config.x4xx_limit.unwrap_or(0),
|
||||
healthcheck: path_config.healthcheck.unwrap_or(true),
|
||||
redirect_to: redirect_link,
|
||||
authorization: path_auth,
|
||||
}));
|
||||
|
||||
+7
-7
@@ -4,7 +4,7 @@ use crate::utils::types::{Extraparams, InnerMapForJson, UpstreamSnapshotForJson,
|
||||
use dashmap::DashMap;
|
||||
use log::{error, info};
|
||||
use privdrop::PrivDrop;
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fmt::Write;
|
||||
@@ -16,8 +16,8 @@ use std::os::unix::fs::MetadataExt;
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::{env, fs, process, thread, time};
|
||||
|
||||
pub fn print_upstreams(upstreams: &UpstreamsDashMap, extraparams: &Extraparams) {
|
||||
@@ -35,8 +35,8 @@ pub fn print_upstreams(upstreams: &UpstreamsDashMap, extraparams: &Extraparams)
|
||||
f.is_ssl,
|
||||
f.is_http2,
|
||||
f.to_https,
|
||||
f.rate_limit.unwrap_or(extraparams.rate_limit.unwrap_or(0)),
|
||||
f.x4xx_limit.unwrap_or(extraparams.x4xx_limit.unwrap_or(0))
|
||||
if f.rate_limit > 0 { f.rate_limit } else { extraparams.rate_limit },
|
||||
if f.x4xx_limit > 0 { f.x4xx_limit } else { extraparams.x4xx_limit }
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -138,9 +138,9 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) {
|
||||
x.port,
|
||||
x.is_http2,
|
||||
x.to_https,
|
||||
x.x4xx_limit.unwrap_or_default(),
|
||||
x.rate_limit.unwrap_or_default(),
|
||||
x.healthcheck.unwrap_or_default(),
|
||||
x.x4xx_limit,
|
||||
x.rate_limit,
|
||||
x.healthcheck,
|
||||
x.authorization
|
||||
)
|
||||
.unwrap_or(());
|
||||
|
||||
+12
-11
@@ -1,8 +1,8 @@
|
||||
use dashmap::DashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
|
||||
pub type UpstreamsDashMap = DashMap<Arc<str>, DashMap<Arc<str>, (Vec<Arc<InnerMap>>, AtomicUsize)>>;
|
||||
|
||||
@@ -11,11 +11,12 @@ pub type Headers = DashMap<Arc<str>, DashMap<Arc<str>, Vec<(String, Arc<str>)>>>
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Extraparams {
|
||||
pub to_https: Option<bool>,
|
||||
pub sticky_sessions: Option<u64>,
|
||||
pub sticky_sessions: u64,
|
||||
pub rate_limit: isize,
|
||||
pub x4xx_limit: u32,
|
||||
pub to_https: bool,
|
||||
pub ssl_verify: bool,
|
||||
pub authentication: Option<Arc<InnerAuth>>,
|
||||
pub rate_limit: Option<isize>,
|
||||
pub x4xx_limit: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
@@ -151,9 +152,9 @@ pub struct InnerMap {
|
||||
pub is_ssl: bool,
|
||||
pub is_http2: bool,
|
||||
pub to_https: bool,
|
||||
pub rate_limit: Option<isize>,
|
||||
pub x4xx_limit: Option<u32>,
|
||||
pub healthcheck: Option<bool>,
|
||||
pub rate_limit: isize,
|
||||
pub x4xx_limit: u32,
|
||||
pub healthcheck: bool,
|
||||
pub redirect_to: Option<Arc<str>>,
|
||||
pub authorization: Option<Arc<InnerAuth>>,
|
||||
}
|
||||
@@ -190,9 +191,9 @@ pub struct InnerMapForJson {
|
||||
pub is_ssl: bool,
|
||||
pub is_http2: bool,
|
||||
pub to_https: bool,
|
||||
pub rate_limit: Option<isize>,
|
||||
pub x4xx_limit: Option<u32>,
|
||||
pub healthcheck: Option<bool>,
|
||||
pub rate_limit: isize,
|
||||
pub x4xx_limit: u32,
|
||||
pub healthcheck: bool,
|
||||
}
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct UpstreamSnapshotForJson {
|
||||
|
||||
Reference in New Issue
Block a user