refactor(proxy): share auth_header_value helper across provider adapters

claude.rs and gemini.rs each defined an identical `hv` closure that wrapped
`HeaderValue::from_str` into a ProxyError::AuthError result, and codex.rs
spelled the same conversion out inline. /simplify reviewers flagged this
as drift-prone copy-paste.

Move the conversion into a single `pub fn auth_header_value` in
providers/adapter.rs and have the three adapters import it locally. Same
error wording everywhere, one place to update if HeaderValue semantics
ever change.
This commit is contained in:
Jason
2026-05-14 08:21:53 +08:00
parent 3c35972548
commit 039784af73
4 changed files with 16 additions and 11 deletions
+2 -3
View File
@@ -177,12 +177,11 @@ impl ProviderAdapter for CodexAdapter {
&self,
auth: &AuthInfo,
) -> Result<Vec<(http::HeaderName, http::HeaderValue)>, ProxyError> {
use super::adapter::auth_header_value;
let bearer = format!("Bearer {}", auth.api_key);
let value = http::HeaderValue::from_str(&bearer)
.map_err(|e| ProxyError::AuthError(format!("invalid auth header value: {e}")))?;
Ok(vec![(
http::HeaderName::from_static("authorization"),
value,
auth_header_value(&bearer)?,
)])
}
}