2026-04-09 00:10:38 +08:00
|
|
|
use super::super::internal;
|
|
|
|
|
use crate::admin_api;
|
2026-04-05 20:23:16 +08:00
|
|
|
use crate::control::GatewayPublicRequestContext;
|
|
|
|
|
use crate::{AppState, GatewayError};
|
2026-04-04 01:40:24 +08:00
|
|
|
use axum::body::{Body, Bytes};
|
|
|
|
|
use axum::http::Response;
|
2026-04-03 14:59:58 +08:00
|
|
|
|
|
|
|
|
pub(super) async fn maybe_build_local_internal_proxy_response(
|
2026-03-31 19:19:04 +08:00
|
|
|
state: &AppState,
|
|
|
|
|
request_context: &GatewayPublicRequestContext,
|
|
|
|
|
remote_addr: &std::net::SocketAddr,
|
2026-04-04 01:40:24 +08:00
|
|
|
request_body: Option<&Bytes>,
|
2026-03-31 19:19:04 +08:00
|
|
|
) -> Result<Option<Response<Body>>, GatewayError> {
|
2026-04-04 01:40:24 +08:00
|
|
|
internal::maybe_build_local_internal_proxy_response_impl(
|
2026-03-31 19:19:04 +08:00
|
|
|
state,
|
|
|
|
|
request_context,
|
|
|
|
|
remote_addr,
|
|
|
|
|
request_body,
|
|
|
|
|
)
|
2026-04-04 01:40:24 +08:00
|
|
|
.await
|
2026-03-31 19:19:04 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-03 14:59:58 +08:00
|
|
|
pub(super) async fn maybe_build_local_admin_proxy_response(
|
2026-03-31 19:19:04 +08:00
|
|
|
state: &AppState,
|
|
|
|
|
request_context: &GatewayPublicRequestContext,
|
2026-04-04 01:40:24 +08:00
|
|
|
request_body: Option<&Bytes>,
|
2026-03-31 19:19:04 +08:00
|
|
|
) -> Result<Option<Response<Body>>, GatewayError> {
|
|
|
|
|
let Some(decision) = request_context.control_decision.as_ref() else {
|
|
|
|
|
return Ok(None);
|
|
|
|
|
};
|
|
|
|
|
if decision.route_class.as_deref() != Some("admin_proxy") {
|
|
|
|
|
return Ok(None);
|
|
|
|
|
}
|
|
|
|
|
if decision.admin_principal.is_none() {
|
|
|
|
|
return Ok(None);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 00:10:38 +08:00
|
|
|
admin_api::maybe_build_local_admin_response(admin_api::AdminRouteRequest::new(
|
2026-04-07 02:50:19 +08:00
|
|
|
state,
|
|
|
|
|
request_context,
|
|
|
|
|
request_body,
|
2026-04-09 00:10:38 +08:00
|
|
|
))
|
|
|
|
|
.await
|
2026-03-31 19:19:04 +08:00
|
|
|
}
|