aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock6
-rw-r--r--Cargo.toml4
-rw-r--r--src/html.rs23
-rw-r--r--src/response.rs12
4 files changed, 21 insertions, 24 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5b86ffe..52593aa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -594,9 +594,9 @@ dependencies = [
[[package]]
name = "germ"
-version = "0.4.3"
+version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "701dd8ad6cb9061a244a85fb4534d9041e68c1c6c22e35040df97dcc7ce12596"
+checksum = "e2c057e745ba976509bc17b35f65364e7cef0ec2c9683d342ca55b92000432f1"
dependencies = [
"anyhow",
"rustls",
@@ -1839,7 +1839,7 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
[[package]]
name = "september"
-version = "0.2.23"
+version = "0.2.24"
dependencies = [
"actix-web",
"anyhow",
diff --git a/Cargo.toml b/Cargo.toml
index 3285cb7..c272109 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,7 +2,7 @@
[package]
name = "september"
-version = "0.2.23"
+version = "0.2.24"
authors = ["Fuwn <[email protected]>"]
edition = "2021"
description = "A simple and efficient Gemini-to-HTTP proxy."
@@ -21,7 +21,7 @@ opt-level = 3
[dependencies]
# Gemini
-germ = { version = "0.4.3", features = ["ast", "meta"] }
+germ = { version = "0.4.4", features = ["ast", "meta"] }
# HTTP
actix-web = "4.7.0"
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),
+ ));
}
}