Add global headers for all upstreams

This commit is contained in:
Ara Sadoyan
2025-03-25 19:19:54 +01:00
parent f3bca5a001
commit 451e1f469e
3 changed files with 32 additions and 24 deletions

View File

@@ -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>() {