use crate::body::extract_body;
use crate::forward::forward_request;
use crate::ProxyState;
use axum::body::Bytes;
use axum::extract::State;
use axum::http::{HeaderMap, StatusCode, Uri};
use axum::response::{IntoResponse, Response};
pub async fn google_handler(
State(state): State<ProxyState>,
uri: Uri,
headers: HeaderMap,
body: Bytes,
) -> Response {
let body = match extract_body(&headers, body) {
Ok(s) => s,
Err(e) => {
return (
StatusCode::BAD_REQUEST,
axum::Json(serde_json::json!({"error": e})),
)
.into_response();
}
};
let base_url = &state.config.providers.google;
let query = uri.query().map(|q| format!("?{}", q)).unwrap_or_default();
let target_url = format!("{}{}{}", base_url, uri.path(), query);
if state.config.verbose {
tracing::info!("Google: passthrough → {}{}", base_url, uri.path());
}
forward_request(
&state.http_client,
"POST",
&target_url,
&headers,
Some(body),
)
.await
}