This commit is contained in:
Mateusz Gruszczyński committed 2026-10-10 00:18:06 +02:00
1 parent ad95bfb050
commit 1431dd47f0
62 files changed
+1360 -198

No files matched your search

+55 -3
View File
@@ -296,7 +296,6 @@ mod authority_tests {
"12.00ms"
);
}
}
#[test]
fn upstream_uri_preserves_nested_url_query_without_rejecting_valid_separators() {
@@ -402,11 +401,64 @@ async fn fallback_terminal_404_html_takes_precedence_over_builtin_error_page() {
Bytes::from_static(b"<html><title>ReactPHP 404</title></html>")
);
// A normal response with no fallback is still eligible for the configured
// global/vhost error-page replacement.
// A proxy-generated response is eligible for configured global/vhost
// pages even when interception of *application* errors is disabled.
let response = Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::empty())
.unwrap();
assert!(should_replace_error_page(&response, false));
}
#[tokio::test]
async fn application_404_is_not_overwritten_by_global_pages_when_interception_is_off() {
use http_body_util::BodyExt;
for source in ["reverse_proxy", "web_server_php"] {
let mut response = Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::from(format!("{source}: origin 404 body")))
.unwrap();
// Both paths use intercept_route_origin_error to set this marker
// once the origin response reaches Response<Body>.
response.extensions_mut().insert(crate::pages::OriginProvidedResponse);
assert!(!should_replace_error_page(&response, false), "{source}");
let bytes = response.into_body().collect().await.unwrap().to_bytes();
assert_eq!(bytes.as_ref(), format!("{source}: origin 404 body").as_bytes());
}
}
#[tokio::test]
async fn compiled_vhost_origin_interception_controls_application_404() {
for enabled in [false, true] {
let mut config = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
config.pages.errors.insert(404, crate::pages::Page {
kind: crate::pages::Kind::Html,
status: Some(503),
html: "RustProxy custom error page".into(),
});
if enabled {
config.vhosts[0].pages.intercept_statuses = vec![404];
}
let snapshot = crate::config::compile(config, 1, &validation_policy()).unwrap();
let route = snapshot.select("localhost", "/").unwrap();
let response = Response::builder().status(StatusCode::NOT_FOUND)
.body(Body::from("application custom 404"))
.unwrap();
let response = intercept_route_origin_error(response, route, &snapshot);
assert_eq!(response.status(), StatusCode::NOT_FOUND);
assert!(response.extensions().get::<crate::pages::OriginProvidedResponse>().is_some());
assert!(!should_replace_error_page(&response, false));
assert_eq!(response.extensions().get::<crate::pages::PageServed>().is_some(), enabled);
if enabled {
assert_eq!(response.headers().get("cache-control").unwrap(), "no-store");
}
let bytes = response.into_body().collect().await.unwrap().to_bytes();
if enabled {
assert_eq!(bytes, "RustProxy custom error page");
} else {
assert_eq!(bytes, "application custom 404");
}
}
}
}