MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / with_config

Method with_config

atomic-remote/src/http/mod.rs:204–246  ·  view source on GitHub ↗

Create a new HTTP remote connection with custom configuration. # Arguments `url` - The base URL for the repository endpoint. `config` - Configuration options. # Example ``` use atomic_remote::http::{HttpRemote, HttpRemoteConfig}; use std::time::Duration; let config = HttpRemoteConfig::new() .with_timeout(Duration::from_secs(60)) .with_header("Authorization", "Bearer token"); let remote = Htt

(url: &str, config: HttpRemoteConfig)

Source from the content-addressed store, hash-verified

202 /// # Ok::<(), atomic_remote::error::RemoteError>(())
203 /// ```
204 pub fn with_config(url: &str, config: HttpRemoteConfig) -> RemoteResult<Self> {
205 let base_url = Url::parse(url)?;
206
207 // Build default headers
208 let mut headers = HeaderMap::new();
209 headers.insert(USER_AGENT, HeaderValue::from_static(ATOMIC_USER_AGENT));
210 headers.insert(
211 ACCEPT_ENCODING,
212 HeaderValue::from_static(ACCEPT_ENCODING_VALUE),
213 );
214
215 // Add extra headers from config
216 for (name, value) in &config.extra_headers {
217 if let (Ok(header_name), Ok(header_value)) = (
218 reqwest::header::HeaderName::try_from(name.as_str()),
219 HeaderValue::from_str(value),
220 ) {
221 headers.insert(header_name, header_value);
222 }
223 }
224
225 // Build the HTTP client
226 let client = Client::builder()
227 .timeout(config.timeout)
228 .connect_timeout(config.connect_timeout)
229 .danger_accept_invalid_certs(config.danger_accept_invalid_certs)
230 .default_headers(headers)
231 .gzip(true)
232 .deflate(true)
233 .build()
234 .map_err(|e| RemoteError::connection_failed(url, e))?;
235
236 // Try to infer repository name from URL path
237 let name = infer_repo_name(&base_url);
238
239 debug!("Created HttpRemote for {} (name: {:?})", base_url, name);
240
241 Ok(Self {
242 base_url,
243 client,
244 name,
245 })
246 }
247
248 /// Get the base URL.
249 pub fn url(&self) -> &Url {

Callers

nothing calls this directly

Calls 7

timeoutMethod · 0.80
infer_repo_nameFunction · 0.70
parseFunction · 0.50
insertMethod · 0.45
as_strMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected