MCPcopy Create free account
hub / github.com/bajrangCoder/setu / to_header

Method to_header

src/components/auth_editor.rs:105–131  ·  view source on GitHub ↗

Generate Authorization header if applicable

(&self)

Source from the content-addressed store, hash-verified

103 pub api_key_in_header: bool, // true = header, false = query param
104}
105
106impl 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 }

Callers 1

get_all_headersMethod · 0.80

Calls 2

base64_encodeFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected