mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 18:37:46 +08:00
refactor: 移除独立 hub/proxy/executor/gateway crate,统一为 gateway tunnel 架构
- 删除 aether-hub、aether-proxy 独立项目及其 Dockerfile/配置 - 删除 crates/aether-executor 和 crates/aether-gateway 全部模块 - 新增 apps/ 目录作为应用入口 - 将 hub 概念重构为 gateway tunnel transport - 将 executor 重构为 execution runtime - 新增 tunnel.rs 合约定义和 testkit tunnel/execution_runtime 模块 - 更新 Python 服务层和测试适配新架构命名
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
use axum::http::Uri;
|
||||
|
||||
use crate::gateway::headers::header_value_str;
|
||||
use crate::gateway::{AppState, GatewayError};
|
||||
|
||||
use super::{resolve_control_route, GatewayControlDecision};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct GatewayPublicRequestContext {
|
||||
pub(crate) trace_id: String,
|
||||
pub(crate) request_method: http::Method,
|
||||
pub(crate) request_path: String,
|
||||
pub(crate) request_query_string: Option<String>,
|
||||
pub(crate) request_content_type: Option<String>,
|
||||
pub(crate) host_header: Option<String>,
|
||||
pub(crate) control_decision: Option<GatewayControlDecision>,
|
||||
}
|
||||
|
||||
impl GatewayPublicRequestContext {
|
||||
pub(crate) fn from_request_parts(
|
||||
trace_id: impl Into<String>,
|
||||
method: &http::Method,
|
||||
uri: &Uri,
|
||||
headers: &http::HeaderMap,
|
||||
control_decision: Option<GatewayControlDecision>,
|
||||
) -> Self {
|
||||
let request_path = if uri.path().starts_with('/') {
|
||||
uri.path().to_string()
|
||||
} else {
|
||||
format!("/{}", uri.path())
|
||||
};
|
||||
let request_query_string = uri.query().map(ToOwned::to_owned);
|
||||
|
||||
Self {
|
||||
trace_id: trace_id.into(),
|
||||
request_method: method.clone(),
|
||||
request_path,
|
||||
request_query_string,
|
||||
request_content_type: header_value_str(headers, http::header::CONTENT_TYPE.as_str()),
|
||||
host_header: header_value_str(headers, http::header::HOST.as_str()),
|
||||
control_decision,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn request_path_and_query(&self) -> String {
|
||||
if let Some(query) = self
|
||||
.request_query_string
|
||||
.as_deref()
|
||||
.filter(|value| !value.is_empty())
|
||||
{
|
||||
format!("{}?{query}", self.request_path)
|
||||
} else {
|
||||
self.request_path.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn resolve_public_request_context(
|
||||
state: &AppState,
|
||||
method: &http::Method,
|
||||
uri: &Uri,
|
||||
headers: &http::HeaderMap,
|
||||
trace_id: &str,
|
||||
) -> Result<GatewayPublicRequestContext, GatewayError> {
|
||||
let control_decision = resolve_control_route(state, method, uri, headers, trace_id).await?;
|
||||
Ok(GatewayPublicRequestContext::from_request_parts(
|
||||
trace_id,
|
||||
method,
|
||||
uri,
|
||||
headers,
|
||||
control_decision,
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user