0.34.13_cleaup_code

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-26 14:14:41 +01:00
1 parent ec46a96a29
commit 5c2e50ec06
87 files changed
+4890 -1338

No files matched your search

+51 -19
View File
@@ -11,9 +11,26 @@ pub(super) async fn php_response(
context: RequestContext,
) -> Response {
let start = Instant::now();
let mut response = php_response_inner(service, php, method, headers, original_uri, script_path, path_info, query, body, context).await;
php.metrics.record(response.status(), start.elapsed().as_micros().min(u64::MAX as u128) as u64);
response.extensions_mut().insert(crate::web_server::metrics::ResponseKind::Php);
let mut response = php_response_inner(
service,
php,
method,
headers,
original_uri,
script_path,
path_info,
query,
body,
context,
)
.await;
php.metrics.record(
response.status(),
start.elapsed().as_micros().min(u64::MAX as u128) as u64,
);
response
.extensions_mut()
.insert(crate::web_server::metrics::ResponseKind::Php);
response
}
@@ -51,15 +68,19 @@ async fn php_response_inner(
return response;
}
};
let mut io = match tokio::time::timeout(php.connect_timeout, connect_fastcgi(&php.endpoint)).await {
Ok(Ok(io)) => io,
Ok(Err(error)) => {
php.metrics.failure(2);
tracing::warn!(%error, service = %service.id, "PHP-FPM connection failed");
return builtin_error_response(StatusCode::BAD_GATEWAY, &method);
}
Err(_) => { php.metrics.failure(1); return builtin_error_response(StatusCode::GATEWAY_TIMEOUT, &method); },
};
let mut io =
match tokio::time::timeout(php.connect_timeout, connect_fastcgi(&php.endpoint)).await {
Ok(Ok(io)) => io,
Ok(Err(error)) => {
php.metrics.failure(2);
tracing::warn!(%error, service = %service.id, "PHP-FPM connection failed");
return builtin_error_response(StatusCode::BAD_GATEWAY, &method);
}
Err(_) => {
php.metrics.failure(1);
return builtin_error_response(StatusCode::GATEWAY_TIMEOUT, &method);
}
};
let params = match fastcgi_params(
service,
php,
@@ -91,8 +112,9 @@ async fn php_response_inner(
let mut body = body;
let mut body_bytes = 0u64;
while let Some(frame) = body.frame().await {
let frame = frame
.map_err(|error| FastCgiRequestWriteError::Io(io::Error::other(error.to_string())))?;
let frame = frame.map_err(|error| {
FastCgiRequestWriteError::Io(io::Error::other(error.to_string()))
})?;
if let Ok(data) = frame.into_data() {
body_bytes = body_bytes.saturating_add(data.len() as u64);
if php.max_request_body_bytes > 0 && body_bytes > php.max_request_body_bytes {
@@ -117,7 +139,10 @@ async fn php_response_inner(
tracing::warn!(%error, service = %service.id, "PHP-FPM request write failed");
return builtin_error_response(StatusCode::BAD_GATEWAY, &method);
}
Err(_) => { php.metrics.failure(3); return builtin_error_response(StatusCode::GATEWAY_TIMEOUT, &method); },
Err(_) => {
php.metrics.failure(3);
return builtin_error_response(StatusCode::GATEWAY_TIMEOUT, &method);
}
}
let mut stdout = Vec::new();
@@ -128,7 +153,7 @@ async fn php_response_inner(
Ok(value) => value,
Err(error) if error.kind() == io::ErrorKind::TimedOut => {
php.metrics.failure(5);
return builtin_error_response(StatusCode::GATEWAY_TIMEOUT, &method)
return builtin_error_response(StatusCode::GATEWAY_TIMEOUT, &method);
}
Err(error) => {
tracing::warn!(%error, service = %service.id, "PHP-FPM response read failed");
@@ -218,17 +243,24 @@ pub(super) fn method_not_allowed_response() -> Response {
response
}
pub(super) fn php_for_path<'a>(service: &'a CompiledService, path: &Path) -> Option<&'a CompiledPhp> {
pub(super) fn php_for_path<'a>(
service: &'a CompiledService,
path: &Path,
) -> Option<&'a CompiledPhp> {
let php = service.php.as_ref()?;
let extension = path
.extension()
.and_then(|value| value.to_str())?
.to_ascii_lowercase();
(php.extensions.contains(&extension) || htaccess::php_extension(service.htaccess.as_ref(), path)).then_some(php)
(php.extensions.contains(&extension)
|| htaccess::php_extension(service.htaccess.as_ref(), path))
.then_some(php)
}
pub(super) fn protected_script_without_handler(service: &CompiledService, path: &Path) -> bool {
if service.php.is_some() { return false; }
if service.php.is_some() {
return false;
}
path.extension()
.and_then(|value| value.to_str())
.map(|value| value.to_ascii_lowercase())