v0.13.9-ha_addon

This commit is contained in:
Mateusz Gruszczyński
2026-09-09 15:19:10 +02:00
parent 4196fbe0ef
commit fa0d4d0754
32 changed files with 1941 additions and 30 deletions
+19 -16
View File
@@ -67,23 +67,26 @@ fn request_base_path(state: &AppState, headers: &HeaderMap) -> String {
}
fn forwarded_prefix(headers: &HeaderMap) -> Option<String> {
let raw = headers
.get("x-forwarded-prefix")?
.to_str()
.ok()?
.split(',')
.next()?
.trim();
if raw.is_empty() || raw == "/" {
return Some(String::new());
// Home Assistant ingress uses X-Ingress-Path. Generic reverse proxies
// commonly use X-Forwarded-Prefix, so support both with HA taking
// precedence when both are present.
for header in ["x-ingress-path", "x-forwarded-prefix"] {
let Some(raw) = headers.get(header).and_then(|value| value.to_str().ok()) else {
continue;
};
let raw = raw.split(',').next().unwrap_or_default().trim();
if raw.is_empty() || raw == "/" {
return Some(String::new());
}
if raw.contains('?')
|| raw.contains('#')
|| raw.split('/').any(|part| matches!(part, "." | ".."))
{
continue;
}
return Some(format!("/{}", raw.trim_matches('/')));
}
if raw.contains('?')
|| raw.contains('#')
|| raw.split('/').any(|part| matches!(part, "." | ".."))
{
return None;
}
Some(format!("/{}", raw.trim_matches('/')))
None
}
async fn app_js() -> Response {
static_response(