1use crate::{AeoError, Document};
2
3const WELL_KNOWN_PATH: &str = "/.well-known/aeo.json";
4const ACCEPT_HEADER: &str = "application/aeo+json, application/json";
5
6pub fn well_known_url(origin: &str) -> String {
11 format!("{}{}", origin.trim_end_matches('/'), WELL_KNOWN_PATH)
12}
13
14pub fn fetch_well_known(origin: &str) -> Result<Document, AeoError> {
19 let url = well_known_url(origin);
20 let response = ureq::get(&url)
21 .set("Accept", ACCEPT_HEADER)
22 .call()
23 .map_err(|e| match e {
24 ureq::Error::Status(status, _) => AeoError::HttpStatus {
25 status,
26 url: url.clone(),
27 },
28 other => AeoError::Http(Box::new(other)),
29 })?;
30
31 let body = response.into_string()?;
32 Document::from_json(&body)
33}