Skip to main content

forge_runtime/gateway/
mod.rs

1mod auth;
2pub mod jwks;
3mod mcp;
4mod multipart;
5pub mod oauth;
6mod request;
7mod response;
8mod rpc;
9mod server;
10mod sse;
11mod tracing;
12
13pub use auth::{AuthConfig, AuthMiddleware, HmacTokenIssuer, build_auth_context_from_claims};
14pub use jwks::{JwksClient, JwksError};
15pub use mcp::{McpState, mcp_get_handler, mcp_post_handler};
16pub use multipart::rpc_multipart_handler;
17pub use oauth::OAuthState;
18pub use request::{BatchRpcRequest, BatchRpcResponse, RpcRequest};
19pub use response::{RpcError, RpcResponse};
20pub use rpc::RpcHandler;
21pub use server::{GatewayConfig, GatewayServer};
22pub use sse::{
23    SseConfig, SsePayload, SseQuery, SseState, sse_handler, sse_job_subscribe_handler,
24    sse_subscribe_handler, sse_unsubscribe_handler, sse_workflow_subscribe_handler,
25};
26pub use tracing::TracingMiddleware;
27
28pub(crate) fn extract_client_ip(headers: &axum::http::HeaderMap) -> Option<String> {
29    headers
30        .get("x-forwarded-for")
31        .and_then(|v| v.to_str().ok())
32        .and_then(|s| s.split(',').next())
33        .map(|s| s.trim().to_string())
34        .filter(|s| !s.is_empty())
35        .or_else(|| {
36            headers
37                .get("x-real-ip")
38                .and_then(|v| v.to_str().ok())
39                .map(|s| s.trim().to_string())
40                .filter(|s| !s.is_empty())
41        })
42}
43
44pub(crate) fn extract_header(headers: &axum::http::HeaderMap, name: &str) -> Option<String> {
45    headers
46        .get(name)
47        .and_then(|v| v.to_str().ok())
48        .filter(|v| !v.is_empty())
49        .map(String::from)
50}