aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/html.rs23
-rw-r--r--src/response.rs12
2 files changed, 16 insertions, 19 deletions
diff --git a/src/html.rs b/src/html.rs
index cf905f8..dc52754 100644
--- a/src/html.rs
+++ b/src/html.rs
@@ -4,13 +4,7 @@ fn link_from_host_href(url: &Url, href: &str) -> Option<String> {
Some(format!(
"gemini://{}{}{}",
url.domain()?,
- {
- if href.starts_with('/') {
- ""
- } else {
- "/"
- }
- },
+ { if href.starts_with('/') { "" } else { "/" } },
href
))
}
@@ -21,8 +15,9 @@ pub fn from_gemini(
url: &Url,
is_proxy: bool,
) -> Option<(String, String)> {
- let ast_tree =
- germ::ast::Ast::from_string(response.content().clone().unwrap_or_default());
+ let ast_tree = germ::ast::Ast::from_string(
+ response.content().as_ref().map_or_else(String::default, String::clone),
+ );
let ast = ast_tree.inner();
let mut html = String::new();
let mut title = String::new();
@@ -67,7 +62,7 @@ pub fn from_gemini(
match node {
Node::Text(text) => html.push_str(&format!("<p>{}</p>", safe(text))),
Node::Link { to, text } => {
- let mut href = to.clone();
+ let mut href = to.to_string();
let mut surface = false;
if href.contains("://") && !href.starts_with("gemini://") {
@@ -159,14 +154,14 @@ pub fn from_gemini(
html.push_str(&format!(
"<p><a href=\"{}\">{}</a> <i>Embedded below</i></p>\n",
href,
- safe(&text.clone().unwrap_or_else(|| to.clone())),
+ safe(text.as_ref().unwrap_or(to)),
));
}
html.push_str(&format!(
"<p><img src=\"{}\" alt=\"{}\" /></p>\n",
safe(&href),
- safe(&text.clone().unwrap_or_else(|| to.clone())),
+ safe(text.as_ref().unwrap_or(to)),
));
continue;
@@ -179,7 +174,7 @@ pub fn from_gemini(
html.push_str(&format!(
"<a href=\"{}\">{}</a>",
href,
- safe(&text.clone().unwrap_or_else(|| to.clone())),
+ safe(text.as_ref().unwrap_or(to)),
));
}
Node::Heading { level, text } => {
@@ -188,7 +183,7 @@ pub fn from_gemini(
}
if title.is_empty() && *level == 1 {
- title = safe(&text.clone()).to_string();
+ title = safe(text).to_string();
}
html.push_str(&format!(
diff --git a/src/response.rs b/src/response.rs
index 73a32e9..07161d5 100644
--- a/src/response.rs
+++ b/src/response.rs
@@ -115,7 +115,9 @@ For example: to proxy "gemini://fuwn.me/uptime", visit "/proxy/fuwn.me/uptime".<
let convert_time_taken = timer.elapsed();
if is_raw {
- html_context.push_str(&response.content().clone().unwrap_or_default());
+ html_context.push_str(
+ &response.content().as_ref().map_or_else(String::default, String::clone),
+ );
return Ok(
HttpResponse::Ok()
@@ -265,7 +267,7 @@ For example: to proxy "gemini://fuwn.me/uptime", visit "/proxy/fuwn.me/uptime".<
</details></body></html>",
url,
response.status(),
- i32::from(response.status().clone()),
+ i32::from(*response.status()),
response.meta(),
response_time_taken.as_nanos() as f64 / 1_000_000.0,
convert_time_taken.as_nanos() as f64 / 1_000_000.0,
@@ -278,9 +280,9 @@ For example: to proxy "gemini://fuwn.me/uptime", visit "/proxy/fuwn.me/uptime".<
path_matches_pattern(r, req.path())
|| path_matches_pattern(r, req.path().trim_end_matches('/'))
}) {
- return Ok(
- HttpResponse::Ok().body(response.content().clone().unwrap_or_default()),
- );
+ return Ok(HttpResponse::Ok().body(
+ response.content().as_ref().map_or_else(String::default, String::clone),
+ ));
}
}