mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
Add global headers for all upstreams
This commit is contained in:
@@ -10,6 +10,7 @@ use std::sync::atomic::AtomicUsize;
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Config {
|
||||
upstreams: HashMap<String, HostConfig>,
|
||||
globals: HashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@@ -57,13 +58,23 @@ pub fn load_yaml_to_dashmap(d: &str, kind: &str) -> Option<(UpstreamsDashMap, He
|
||||
for (path, path_config) in host_config.paths {
|
||||
let mut server_list = Vec::new();
|
||||
let mut hl = Vec::new();
|
||||
|
||||
// Set global headers
|
||||
for headers in parsed.globals.get("headers").iter().by_ref() {
|
||||
for header in headers.iter() {
|
||||
if let Some((key, val)) = header.split_once(':') {
|
||||
hl.push((key.to_string(), val.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set per host/path headers
|
||||
for header in path_config.headers.iter().by_ref() {
|
||||
if let Some((key, val)) = header.split_once(':') {
|
||||
hl.push((key.to_string(), val.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
header_list.insert(path.clone(), hl);
|
||||
// println!(" {:?} == {:?}", hostname, header_list);
|
||||
for server in path_config.servers {
|
||||
if let Some((ip, port_str)) = server.split_once(':') {
|
||||
if let Ok(port) = port_str.parse::<u16>() {
|
||||
|
||||
@@ -68,15 +68,16 @@ impl BackgroundService for LB {
|
||||
val = rx.next() => {
|
||||
match val {
|
||||
Some(ss) => {
|
||||
let foo = compare_dashmaps(&*self.ump_full, &ss.0);
|
||||
if !foo {
|
||||
clone_dashmap_into(&ss.0, &self.ump_full);
|
||||
clone_dashmap_into(&ss.0, &self.ump_upst);
|
||||
for (k,v) in ss.1 {
|
||||
self.headers.insert(k,v);
|
||||
}
|
||||
print_upstreams(&self.ump_full);
|
||||
// let foo = compare_dashmaps(&*self.ump_full, &ss.0);
|
||||
// println!("{:?}", ss.1);
|
||||
// if !foo {
|
||||
clone_dashmap_into(&ss.0, &self.ump_full);
|
||||
clone_dashmap_into(&ss.0, &self.ump_upst);
|
||||
for (k,v) in ss.1 {
|
||||
self.headers.insert(k,v);
|
||||
}
|
||||
print_upstreams(&self.ump_full);
|
||||
// }
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
@@ -265,5 +266,6 @@ impl ProxyHttp for LB {
|
||||
async fn logging(&self, session: &mut Session, _e: Option<&pingora::Error>, ctx: &mut Self::CTX) {
|
||||
let response_code = session.response_written().map_or(0, |resp| resp.status.as_u16());
|
||||
debug!("{}, response code: {response_code}", self.request_summary(session, ctx));
|
||||
info!("{}, response code: {response_code}", self.request_summary(session, ctx));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user