Skip to main content

shift_proxy/routes/
google.rs

1//! Google route handler — POST /v1beta/models/* and /v1/models/*
2//!
3//! Pure passthrough — no optimization. Google payload parsing is not yet
4//! implemented in shift-core (matches the TS proxy behavior).
5//! Query params are preserved (may contain API keys — redacted in logs).
6
7use crate::forward::forward_request;
8use crate::ProxyState;
9use axum::extract::State;
10use axum::http::{HeaderMap, Uri};
11use axum::response::Response;
12
13/// POST /v1beta/models/* or /v1/models/* — forward to Google unchanged.
14pub async fn google_handler(
15    State(state): State<ProxyState>,
16    uri: Uri,
17    headers: HeaderMap,
18    body: String,
19) -> Response {
20    let base_url = &state.config.providers.google;
21    let query = uri.query().map(|q| format!("?{}", q)).unwrap_or_default();
22    let target_url = format!("{}{}{}", base_url, uri.path(), query);
23
24    if state.config.verbose {
25        // Redact query params from log output (may contain API keys)
26        tracing::info!("Google: passthrough → {}{}", base_url, uri.path());
27    }
28
29    forward_request(
30        &state.http_client,
31        "POST",
32        &target_url,
33        &headers,
34        Some(body),
35    )
36    .await
37}