v0.29.3
This commit is contained in:
1 parent
68678e98be
commit
b3bc56cd42
16 files changed
+230
-54
No files matched your search
@@ -8,6 +8,11 @@ struct InternalFallbackRoute {
|
||||
#[derive(Clone)]
|
||||
struct FinalRouteContext(crate::config::CompiledRoute);
|
||||
|
||||
/// The named location has already produced the terminal HTTP response.
|
||||
/// In particular, do not replace its 404 HTML with a global/vhost error page.
|
||||
#[derive(Clone, Copy)]
|
||||
struct ErrorFallbackResponse;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ErrorFallbackRequest {
|
||||
method: Method,
|
||||
@@ -88,6 +93,21 @@ async fn prepare_error_fallback_body(request: &mut Request, enabled: bool) -> Re
|
||||
return Ok(ErrorFallbackBody::Replayable(Bytes::new()));
|
||||
}
|
||||
let Some(length) = request.body().size_hint().exact() else {
|
||||
// HTTP/2 and HTTP/3 frequently expose an *empty* GET/HEAD body as a
|
||||
// stream with no exact size hint. Refusing to inspect that stream
|
||||
// silently disables the configured 404 fallback. Only peek for safe
|
||||
// bodyless methods; an actual payload is replayed back into the
|
||||
// original request and is never discarded or forwarded twice.
|
||||
if request.method() == Method::GET || request.method() == Method::HEAD {
|
||||
return match empty_for_cache(request).await {
|
||||
Ok(true) => Ok(ErrorFallbackBody::Replayable(Bytes::new())),
|
||||
Ok(false) => Ok(ErrorFallbackBody::Unavailable),
|
||||
Err(_) => Err(error(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"RustProxy: invalid or incomplete request body\n",
|
||||
)),
|
||||
};
|
||||
}
|
||||
return Ok(ErrorFallbackBody::Unavailable);
|
||||
};
|
||||
if length > MAX_ERROR_FALLBACK_REPLAY_BODY_BYTES {
|
||||
@@ -131,6 +151,13 @@ async fn execute_error_fallback(
|
||||
.select_internal_on(host, &frontend.id, &fallback.target, local.0, tls)
|
||||
.cloned()
|
||||
else {
|
||||
tracing::warn!(
|
||||
vhost = %frontend.id,
|
||||
route = %route.id,
|
||||
target = %fallback.target,
|
||||
status = status.as_u16(),
|
||||
"error fallback target could not be resolved on this frontend"
|
||||
);
|
||||
return None;
|
||||
};
|
||||
let ErrorFallbackBody::Replayable(body) = body else {
|
||||
@@ -148,6 +175,7 @@ async fn execute_error_fallback(
|
||||
},
|
||||
);
|
||||
let mut response = Box::pin(forward_request(state, peer, local, request)).await;
|
||||
response.extensions_mut().insert(ErrorFallbackResponse);
|
||||
if response.extensions().get::<FinalRouteContext>().is_none() {
|
||||
response.extensions_mut().insert(FinalRouteContext(target));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user