This commit is contained in:
Mateusz Gruszczyński committed 2026-10-21 14:39:51 +02:00
1 parent e037190c14
commit 5cb3b37627
37 files changed
+1031 -138

No files matched your search

+1
View File
@@ -253,6 +253,7 @@ pub struct CompiledFrontend {
pub backend_timing_header: bool,
pub rate_limit: crate::rate_limit::Settings,
pub method_policy: crate::vhost::MethodPolicy,
pub content_type_policy: crate::vhost::ContentTypePolicy,
pub basic_auth: Option<crate::basic_auth::Compiled>,
pub metrics: Arc<crate::metrics::VhostMetrics>,
pub server_header: crate::settings::ServerHeader,
+51 -43
View File
@@ -123,15 +123,19 @@ fn compile_routing(
// This is important when the backend URL is an IP shared by several vhosts.
if pool_settings.health_check.host.is_none()
&& (pool_settings.health_check.mode == crate::balance::HealthMode::Http
|| host.backends.iter().any(|member| member.health_check.as_ref()
.is_some_and(|health| health.mode == crate::balance::HealthMode::Http
&& health.host.is_none())))
|| host.backends.iter().any(|member| {
member.health_check.as_ref().is_some_and(|health| {
health.mode == crate::balance::HealthMode::Http && health.host.is_none()
})
}))
{
pool_settings.health_check.host = host
.frontend
.hosts
.iter()
.find(|name| !name.starts_with("*.") && name.parse::<std::net::IpAddr>().is_err())
.find(|name| {
!name.starts_with("*.") && name.parse::<std::net::IpAddr>().is_err()
})
.cloned();
}
let mut pool = crate::balance::Pool::new(
@@ -173,15 +177,17 @@ fn compile_routing(
.as_ref()
.map(|base| crate::tls::variant(base, &tls_policy, false))
.transpose()?;
let profile_policies: Vec<crate::acl::ProfileAccess> = crate::acl::profile_ids(
host.acl_profile_id.as_deref(), &host.acl_profile_ids,
).map(|id| {
let (acl, countries) = acl_profiles.get(id).cloned().ok_or_else(|| {
anyhow::anyhow!("vhost {} references unknown ACL profile {}", host.id, id)
})?;
Ok(crate::acl::ProfileAccess { acl, countries })
}).collect::<Result<_>>()?;
let (profile_acl, profile_country_access) = profile_policies.first()
let profile_policies: Vec<crate::acl::ProfileAccess> =
crate::acl::profile_ids(host.acl_profile_id.as_deref(), &host.acl_profile_ids)
.map(|id| {
let (acl, countries) = acl_profiles.get(id).cloned().ok_or_else(|| {
anyhow::anyhow!("vhost {} references unknown ACL profile {}", host.id, id)
})?;
Ok(crate::acl::ProfileAccess { acl, countries })
})
.collect::<Result<_>>()?;
let (profile_acl, profile_country_access) = profile_policies
.first()
.map(|entry| (entry.acl.clone(), entry.countries.clone()))
.unwrap_or_else(|| (None, crate::rate_limit::CountryAccess::default()));
let frontend = Arc::new(CompiledFrontend {
@@ -205,6 +211,7 @@ fn compile_routing(
backend_timing_header: host.backend_timing_header,
rate_limit: host.rate_limit.clone(),
method_policy: host.method_policy.clone(),
content_type_policy: host.content_type_policy.clone(),
basic_auth: host.basic_auth.compile()?,
server_header: host
.server_header
@@ -360,41 +367,42 @@ fn compile_routing(
}
}
if host.enabled && route.enabled {
let (source, route_pool, backend) = if route.response.is_some() || route.redirect.is_some() {
// Local return/redirect is handled before source dispatch and needs no origin.
(CompiledSource::ReverseProxy, None, None)
} else {
match &route.source {
crate::vhost::Source::ReverseProxy => {
let pool = pool.as_ref().ok_or_else(|| {
anyhow::anyhow!(
let (source, route_pool, backend) =
if route.response.is_some() || route.redirect.is_some() {
// Local return/redirect is handled before source dispatch and needs no origin.
(CompiledSource::ReverseProxy, None, None)
} else {
match &route.source {
crate::vhost::Source::ReverseProxy => {
let pool = pool.as_ref().ok_or_else(|| {
anyhow::anyhow!(
"vhost {} location {} Reverse Proxy source has no backend pool",
host.id,
route.id
)
})?;
let backend = if let Some(id) = route.backend_id.as_deref() {
pool.members
.iter()
.find(|member| member.definition.id == id)
.map(|member| member.backend.clone())
.ok_or_else(|| anyhow::anyhow!("unknown backend {id}"))?
} else {
pool.members[0].backend.clone()
};
(
CompiledSource::ReverseProxy,
Some(pool.clone()),
Some(backend),
)
})?;
let backend = if let Some(id) = route.backend_id.as_deref() {
pool.members
.iter()
.find(|member| member.definition.id == id)
.map(|member| member.backend.clone())
.ok_or_else(|| anyhow::anyhow!("unknown backend {id}"))?
} else {
pool.members[0].backend.clone()
};
(
CompiledSource::ReverseProxy,
Some(pool.clone()),
Some(backend),
)
}
crate::vhost::Source::WebServer { web_service_id } => (
CompiledSource::WebServer(web_services[web_service_id].clone()),
None,
None,
),
}
crate::vhost::Source::WebServer { web_service_id } => (
CompiledSource::WebServer(web_services[web_service_id].clone()),
None,
None,
),
}
};
};
let compiled = Arc::new(CompiledRoute {
backend_id: route.backend_id.clone(),
bindings: frontend.bindings.clone(),