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