1use http::ureq::http::Uri;
10
11use crate::{Error, Result};
12
13pub(crate) fn format_key_server_uri(uri: Uri, email: &str) -> Result<Uri> {
17 let authority = uri.host().unwrap_or("localhost");
18 let scheme = match uri.scheme_str() {
19 Some("hkps") => "https",
20 _ => "http",
21 };
22
23 let pks_path = format!("pks/lookup?op=get&search={email}");
24 let path = if uri.path().is_empty() {
25 String::from("/") + &pks_path
26 } else {
27 uri.path().to_owned() + &pks_path
28 };
29
30 let uri = Uri::builder()
31 .scheme(scheme)
32 .authority(authority)
33 .path_and_query(path)
34 .build()
35 .map_err(|err| Error::BuildKeyServerUriError(err.into(), uri))?;
36
37 Ok(uri)
38}