Generate Authorization header if applicable
(&self)
| 103 | pub api_key_in_header: bool, // true = header, false = query param |
| 104 | } |
| 105 | |
| 106 | impl AuthConfig { |
| 107 | /// Generate Authorization header if applicable |
| 108 | pub fn to_header(&self) -> Option<(String, String)> { |
| 109 | match self.auth_type { |
| 110 | AuthType::None => None, |
| 111 | AuthType::Basic => { |
| 112 | let credentials = format!("{}:{}", self.username, self.password); |
| 113 | let encoded = base64::engine::general_purpose::STANDARD.encode(credentials); |
| 114 | Some(("Authorization".to_string(), format!("Basic {}", encoded))) |
| 115 | } |
| 116 | AuthType::Bearer => { |
| 117 | if self.token.is_empty() { |
| 118 | None |
| 119 | } else { |
| 120 | Some(( |
| 121 | "Authorization".to_string(), |
| 122 | format!("Bearer {}", self.token), |
| 123 | )) |
| 124 | } |
| 125 | } |
| 126 | AuthType::ApiKey => { |
| 127 | if self.api_key_in_header && !self.api_key_name.is_empty() { |
| 128 | Some((self.api_key_name.clone(), self.api_key_value.clone())) |
| 129 | } else { |
| 130 | None |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
no test coverage detected