use http::ureq::http::Uri;
use crate::{Error, Result};
pub(crate) fn format_key_server_uri(uri: Uri, email: &str) -> Result<Uri> {
let authority = uri.host().unwrap_or("localhost");
let scheme = match uri.scheme_str() {
Some("hkps") => "https",
_ => "http",
};
let pks_path = format!("pks/lookup?op=get&search={email}");
let path = if uri.path().is_empty() {
String::from("/") + &pks_path
} else {
uri.path().to_owned() + &pks_path
};
let uri = Uri::builder()
.scheme(scheme)
.authority(authority)
.path_and_query(path)
.build()
.map_err(|err| Error::BuildKeyServerUriError(err.into(), uri))?;
Ok(uri)
}