diff --git a/src/utils/kuberconsul.rs b/src/utils/kuberconsul.rs index 03a9e66..34d09e9 100644 --- a/src/utils/kuberconsul.rs +++ b/src/utils/kuberconsul.rs @@ -115,7 +115,7 @@ impl ServiceDiscovery for KubernetesDiscovery { if let Some(kuber) = config.kubernetes.clone() { if let Some(svc) = kuber.services { for service in svc { - let header_list: DashMap, Vec<(Arc, Arc)>> = DashMap::new(); + let header_list: DashMap, Vec<(String, Arc)>> = DashMap::new(); let mut hl = Vec::new(); build_headers(&service.client_headers, config.as_ref(), &mut hl); if !hl.is_empty() { diff --git a/src/utils/parceyaml.rs b/src/utils/parceyaml.rs index e9443b9..80bd579 100644 --- a/src/utils/parceyaml.rs +++ b/src/utils/parceyaml.rs @@ -68,27 +68,27 @@ pub async fn load_configuration(d: &str, kind: &str) -> (Option, } async fn populate_headers_and_auth(config: &mut Configuration, parsed: &Config) { - let mut ch: Vec<(Arc, Arc)> = Vec::new(); + let mut ch: Vec<(String, Arc)> = Vec::new(); if let Some(headers) = &parsed.client_headers { for header in headers { if let Some((key, val)) = header.split_once(':') { - ch.push((Arc::from(key), Arc::from(val))); + ch.push((key.to_string(), Arc::from(val))); } } } - let global_headers: DashMap, Vec<(Arc, Arc)>> = DashMap::new(); + let global_headers: DashMap, Vec<(String, Arc)>> = DashMap::new(); global_headers.insert(Arc::from("/"), ch); config.client_headers.insert(Arc::from("GLOBAL_CLIENT_HEADERS"), global_headers); - let mut sh: Vec<(Arc, Arc)> = Vec::new(); + let mut sh: Vec<(String, Arc)> = Vec::new(); if let Some(headers) = &parsed.server_headers { for header in headers { if let Some((key, val)) = header.split_once(':') { - sh.push((Arc::from(key.trim()), Arc::from(val.trim()))); + sh.push((key.to_string(), Arc::from(val.trim()))); } } } - let server_global_headers: DashMap, Vec<(Arc, Arc)>> = DashMap::new(); + let server_global_headers: DashMap, Vec<(String, Arc)>> = 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; @@ -119,8 +119,8 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) { if let Some(rate) = &path_config.rate_limit { info!("Applied Rate Limit for {} : {} request per second", hostname, rate); } - let mut hl: Vec<(Arc, Arc)> = Vec::new(); - let mut sl: Vec<(Arc, Arc)> = Vec::new(); + let mut hl: Vec<(String, Arc)> = Vec::new(); + let mut sl: Vec<(String, Arc)> = Vec::new(); build_headers(&path_config.client_headers, config, &mut hl); build_headers(&path_config.server_headers, config, &mut sl); client_header_list.insert(Arc::from(path.as_str()), hl); @@ -254,11 +254,11 @@ fn log_builder(conf: &AppConfig) { env_logger::builder().init(); } -pub fn build_headers(path_config: &Option>, _config: &Configuration, hl: &mut Vec<(Arc, Arc)>) { +pub fn build_headers(path_config: &Option>, _config: &Configuration, hl: &mut Vec<(String, Arc)>) { if let Some(headers) = &path_config { for header in headers { if let Some((key, val)) = header.split_once(':') { - hl.push((Arc::from(key.trim()), Arc::from(val.trim()))); + hl.push((key.trim().to_string(), Arc::from(val.trim()))); } } } diff --git a/src/utils/structs.rs b/src/utils/structs.rs index 57301bf..1795bf2 100644 --- a/src/utils/structs.rs +++ b/src/utils/structs.rs @@ -7,7 +7,7 @@ use std::sync::Arc; pub type UpstreamsDashMap = DashMap, DashMap, (Vec>, AtomicUsize)>>; pub type UpstreamsIdMap = DashMap>; -pub type Headers = DashMap, DashMap, Vec<(Arc, Arc)>>>; +pub type Headers = DashMap, DashMap, Vec<(String, Arc)>>>; #[derive(Clone, Debug, Default)] pub struct Extraparams { diff --git a/src/utils/tools.rs b/src/utils/tools.rs index d43669a..f170c8c 100644 --- a/src/utils/tools.rs +++ b/src/utils/tools.rs @@ -146,7 +146,7 @@ pub fn compare_dashmaps(map1: &UpstreamsDashMap, map2: &UpstreamsDashMap) -> boo true } -pub fn merge_headers(target: &DashMap, Vec<(Arc, Arc)>>, source: &DashMap, Vec<(Arc, Arc)>>) { +pub fn merge_headers(target: &DashMap, Vec<(String, Arc)>>, source: &DashMap, Vec<(String, Arc)>>) { for entry in source.iter() { let global_key = entry.key().clone(); let global_values = entry.value().clone(); diff --git a/src/web/gethosts.rs b/src/web/gethosts.rs index efef9ea..bfc0016 100644 --- a/src/web/gethosts.rs +++ b/src/web/gethosts.rs @@ -6,8 +6,8 @@ use std::sync::Arc; #[derive(Debug, Clone)] pub struct GetHostsReturHeaders { - pub client_headers: Option, Arc)>>, - pub server_headers: Option, Arc)>>, + pub client_headers: Option)>>, + pub server_headers: Option)>>, } #[async_trait] diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs index 093f881..7c1338c 100644 --- a/src/web/proxyhttp.rs +++ b/src/web/proxyhttp.rs @@ -49,7 +49,7 @@ pub struct Context { hostname: Option>, upstream_peer: Option>, extraparams: arc_swap::Guard>, - client_headers: Option, Arc)>>, + client_headers: Option)>>, } #[async_trait] @@ -132,7 +132,7 @@ impl ProxyHttp for LB { if let Some(stream) = session.stream() { if stream.get_ssl().is_none() { if let Some(host) = _ctx.hostname.as_ref() { - let port = self.config.proxy_port_tls.clone().unwrap_or_else(|| "443".to_string()); + let port = self.config.proxy_port_tls.as_deref().unwrap_or("443"); let uri = session.req_header().uri.path(); let capacity = host.len() + uri.len() + 8; let mut s = String::with_capacity(capacity); @@ -258,7 +258,7 @@ impl ProxyHttp for LB { if let Some(sh) = server_headers { for (k, v) in sh { - upstream_request.insert_header(k.to_string(), v.as_ref())?; + upstream_request.insert_header(k, v.as_ref())?; } } if let Some(ch) = client_headers { @@ -281,13 +281,18 @@ impl ProxyHttp for LB { REVERSE_STORE.insert(hh.clone(), bid.clone()); hh }; - let _ = _upstream_response.insert_header("set-cookie", format!("backend_id={}; Path=/; Max-Age=600; HttpOnly; SameSite=Lax", tt)); + // let _ = _upstream_response.insert_header("set-cookie", format!("backend_id={}; Path=/; Max-Age=600; HttpOnly; SameSite=Lax", tt)); + let mut buf = String::with_capacity(80); + buf.push_str("backend_id="); + buf.push_str(&tt); + buf.push_str("; Path=/; Max-Age=600; HttpOnly; SameSite=Lax"); + let _ = _upstream_response.insert_header("set-cookie", buf.as_str()); } } if let Some(client_headers) = &ctx.client_headers { for (k, v) in client_headers.iter() { - _upstream_response.append_header(k.to_string(), v.as_ref())?; + _upstream_response.append_header(k.clone(), v.as_ref())?; } } @@ -304,7 +309,8 @@ impl ProxyHttp for LB { code: session.response_written().map(|resp| resp.status), latency: ctx.start_time.elapsed(), version: session.req_header().version, - upstream: ctx.hostname.clone().unwrap_or(Arc::from("localhost")), + // upstream: ctx.hostname.clone().unwrap_or(Arc::from("localhost")), + upstream: ctx.hostname.take().unwrap_or_else(|| Arc::from("localhost")), }; calc_metrics(m); }