v0.38.0
This commit is contained in:
1 parent
df0e39b899
commit
21aef61dd5
35 files changed
+1360
-100
No files matched your search
@@ -178,7 +178,7 @@ fn compile_routing(
|
||||
.hosts
|
||||
.iter()
|
||||
.find(|name| {
|
||||
!name.starts_with("*.") && name.parse::<std::net::IpAddr>().is_err()
|
||||
!name.starts_with('*') && name.parse::<std::net::IpAddr>().is_err()
|
||||
})
|
||||
.cloned();
|
||||
}
|
||||
|
||||
+13
-2
@@ -3,7 +3,9 @@ impl Snapshot {
|
||||
if let Some(value) = lookup(host) {
|
||||
return Some(value);
|
||||
}
|
||||
let last_dot = host.rfind('.')?;
|
||||
let Some(last_dot) = host.rfind('.') else {
|
||||
return lookup(CATCH_ALL_HOST);
|
||||
};
|
||||
let mut wildcard = [0u8; 256];
|
||||
wildcard[..2].copy_from_slice(b"*.");
|
||||
for (index, _) in host.match_indices('.') {
|
||||
@@ -23,7 +25,7 @@ impl Snapshot {
|
||||
return Some(value);
|
||||
}
|
||||
}
|
||||
None
|
||||
lookup(CATCH_ALL_HOST)
|
||||
}
|
||||
pub fn host_allowed(&self, host: &str, peer: IpAddr) -> bool {
|
||||
if self.host_acls.is_empty() {
|
||||
@@ -431,6 +433,15 @@ pub fn normalize_host(value: &str) -> Result<String> {
|
||||
);
|
||||
Ok(host)
|
||||
}
|
||||
pub const CATCH_ALL_HOST: &str = "*";
|
||||
|
||||
pub fn normalize_frontend_host(value: &str) -> Result<String> {
|
||||
if value.trim() == CATCH_ALL_HOST {
|
||||
return Ok(CATCH_ALL_HOST.into());
|
||||
}
|
||||
normalize_host_pattern(value)
|
||||
}
|
||||
|
||||
pub fn normalize_host_pattern(value: &str) -> Result<String> {
|
||||
let value = value.trim();
|
||||
if let Some(base) = value.strip_prefix("*.") {
|
||||
|
||||
@@ -25,6 +25,33 @@ mod tests {
|
||||
config
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn catch_all_host_serves_unmatched_names_after_exact_and_wildcard_hosts() {
|
||||
let mut config = demo_config("127.0.0.1:9000".parse().unwrap());
|
||||
let mut catch_all = config.vhosts[0].clone();
|
||||
catch_all.id = "catch-all".into();
|
||||
catch_all.frontend.hosts = vec![" * ".into()];
|
||||
config.vhosts.push(catch_all);
|
||||
let snapshot = compile(config, 1, &policy()).unwrap();
|
||||
let local = "127.0.0.1:8080".parse().unwrap();
|
||||
let vhost = |host: &str| snapshot.frontend(host, local, false).map(|f| f.id.clone());
|
||||
assert_eq!(vhost("localhost").as_deref(), Some("demo"));
|
||||
assert_eq!(vhost("demo.localhost").as_deref(), Some("demo"));
|
||||
for host in ["192.168.1.50", "app.example.org", "intranet"] {
|
||||
assert_eq!(vhost(host).as_deref(), Some("catch-all"), "{host}");
|
||||
assert!(snapshot.select_on(host, "/", local, false).is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn catch_all_host_is_only_valid_alone() {
|
||||
let mut config = demo_config("127.0.0.1:9000".parse().unwrap());
|
||||
config.vhosts[0].frontend.hosts = vec!["*.*".into()];
|
||||
assert!(compile(config.clone(), 1, &policy()).is_err());
|
||||
config.vhosts[0].frontend.hosts = vec!["*".into(), "*".into()];
|
||||
assert!(compile(config, 1, &policy()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configuration_above_legacy_limit_compiles() {
|
||||
let config = config_with_large_responses(5);
|
||||
|
||||
Reference in new issue
Block a user