pub fn is_work_around_uri(uri: &str, http_or_https: &str, protocol: &str) -> bool {
uri
.strip_prefix(http_or_https)
.and_then(|rest| rest.strip_prefix("://"))
.and_then(|rest| rest.strip_prefix(protocol))
.and_then(|rest| rest.strip_prefix("."))
.is_some()
}
pub fn apply_uri_work_around(uri: &str, http_or_https: &str, protocol: &str) -> String {
uri.replace(
&original_uri_prefix(protocol),
&work_around_uri_prefix(http_or_https, protocol),
)
}
pub fn revert_uri_work_around(uri: &str, http_or_https: &str, protocol: &str) -> String {
uri.replace(
&work_around_uri_prefix(http_or_https, protocol),
&original_uri_prefix(protocol),
)
}
pub fn original_uri_prefix(protocol: &str) -> String {
format!("{protocol}://")
}
pub fn work_around_uri_prefix(http_or_https: &str, protocol: &str) -> String {
format!("{http_or_https}://{protocol}.")
}
#[cfg(test)]
mod tests {
use super::is_work_around_uri;
#[test]
fn checks_if_custom_protocol_uri() {
let scheme = "http";
let uri = "http://wry.localhost/path/to/page";
assert!(is_work_around_uri(uri, scheme, "wry"));
assert!(!is_work_around_uri(uri, scheme, "asset"));
}
}