cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
use super::http_client::{HttpClient, HttpResponse};

/// Production HTTP client backed by `ureq`.
pub struct UreqClient;

impl HttpClient for UreqClient {
    fn get(&self, url: &str, headers: &[(&str, &str)]) -> anyhow::Result<HttpResponse> {
        let mut req = ureq::get(url);
        for &(name, value) in headers {
            req = req.set(name, value);
        }
        let resp = req
            .call()
            .map_err(|e| anyhow::anyhow!("HTTP request failed: {e}"))?;
        let status = resp.status();
        let body = resp
            .into_string()
            .map_err(|e| anyhow::anyhow!("failed to read response body: {e}"))?;
        Ok(HttpResponse { status, body })
    }
}