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