cookie_agent_models/adapters/
headers.rs1use std::collections::BTreeMap;
2
3use crate::{
4 adapters::OvenAdapterFamily,
5 authoring::{AuthDefinition, HeaderName, SafeStaticHeaderValue},
6 recipes::validate_auth_definition,
7};
8
9const OWNED: &[&str] = &[
10 "accept",
11 "anthropic-beta",
12 "anthropic-version",
13 "connection",
14 "content-length",
15 "content-type",
16 "host",
17 "proxy-authorization",
18 "transfer-encoding",
19];
20
21#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
22pub enum StaticHeaderError {
23 #[error("unsupported_auth_method")]
24 Auth,
25 #[error("static_header_owned")]
26 Owned,
27}
28
29pub fn validate_static_headers(
30 family: OvenAdapterFamily,
31 auth: &AuthDefinition,
32 headers: &BTreeMap<HeaderName, SafeStaticHeaderValue>,
33) -> Result<(), StaticHeaderError> {
34 validate_auth_definition(auth, family.allowed_auth_methods())
35 .map_err(|_| StaticHeaderError::Auth)?;
36 if headers
37 .keys()
38 .any(|header| OWNED.contains(&header.as_str()) || header.as_str().starts_with("x-amz-"))
39 {
40 return Err(StaticHeaderError::Owned);
41 }
42 Ok(())
43}