atmos/os_lib/web_engine/
referrer.rs1use alloc::format;
13use alloc::string::String;
14
15pub fn referrer_for(
20 from_is_https: bool,
21 from_host: &str,
22 from_path: &str,
23 to_is_https: bool,
24 to_host: &str,
25) -> Option<String> {
26 if from_host.is_empty() {
27 return None;
28 }
29 if from_is_https && !to_is_https {
30 return None;
31 }
32 let scheme = if from_is_https { "https" } else { "http" };
33 let same_origin = from_is_https == to_is_https && from_host.eq_ignore_ascii_case(to_host);
34 if same_origin {
35 let path = from_path.split('#').next().unwrap_or("");
36 let path = if path.starts_with('/') { String::from(path) } else { format!("/{}", path) };
37 Some(format!("{}://{}{}", scheme, from_host, path))
38 } else {
39 Some(format!("{}://{}/", scheme, from_host))
40 }
41}