mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 11:43:57 +08:00
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:
@@ -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)?,
|
||||
)])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user