♻️ Simple & Efficient Gemini-to-HTTP Proxy fuwn.net
proxy gemini-protocol protocol gemini http rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: remove all explicit clones

Fuwn 55546086 45025ee0

+21 -24
+3 -3
Cargo.lock
··· 594 594 595 595 [[package]] 596 596 name = "germ" 597 - version = "0.4.3" 597 + version = "0.4.4" 598 598 source = "registry+https://github.com/rust-lang/crates.io-index" 599 - checksum = "701dd8ad6cb9061a244a85fb4534d9041e68c1c6c22e35040df97dcc7ce12596" 599 + checksum = "e2c057e745ba976509bc17b35f65364e7cef0ec2c9683d342ca55b92000432f1" 600 600 dependencies = [ 601 601 "anyhow", 602 602 "rustls", ··· 1839 1839 1840 1840 [[package]] 1841 1841 name = "september" 1842 - version = "0.2.23" 1842 + version = "0.2.24" 1843 1843 dependencies = [ 1844 1844 "actix-web", 1845 1845 "anyhow",
+2 -2
Cargo.toml
··· 2 2 3 3 [package] 4 4 name = "september" 5 - version = "0.2.23" 5 + version = "0.2.24" 6 6 authors = ["Fuwn <contact@fuwn.me>"] 7 7 edition = "2021" 8 8 description = "A simple and efficient Gemini-to-HTTP proxy." ··· 21 21 22 22 [dependencies] 23 23 # Gemini 24 - germ = { version = "0.4.3", features = ["ast", "meta"] } 24 + germ = { version = "0.4.4", features = ["ast", "meta"] } 25 25 26 26 # HTTP 27 27 actix-web = "4.7.0"
+9 -14
src/html.rs
··· 4 4 Some(format!( 5 5 "gemini://{}{}{}", 6 6 url.domain()?, 7 - { 8 - if href.starts_with('/') { 9 - "" 10 - } else { 11 - "/" 12 - } 13 - }, 7 + { if href.starts_with('/') { "" } else { "/" } }, 14 8 href 15 9 )) 16 10 } ··· 21 15 url: &Url, 22 16 is_proxy: bool, 23 17 ) -> Option<(String, String)> { 24 - let ast_tree = 25 - germ::ast::Ast::from_string(response.content().clone().unwrap_or_default()); 18 + let ast_tree = germ::ast::Ast::from_string( 19 + response.content().as_ref().map_or_else(String::default, String::clone), 20 + ); 26 21 let ast = ast_tree.inner(); 27 22 let mut html = String::new(); 28 23 let mut title = String::new(); ··· 67 62 match node { 68 63 Node::Text(text) => html.push_str(&format!("<p>{}</p>", safe(text))), 69 64 Node::Link { to, text } => { 70 - let mut href = to.clone(); 65 + let mut href = to.to_string(); 71 66 let mut surface = false; 72 67 73 68 if href.contains("://") && !href.starts_with("gemini://") { ··· 159 154 html.push_str(&format!( 160 155 "<p><a href=\"{}\">{}</a> <i>Embedded below</i></p>\n", 161 156 href, 162 - safe(&text.clone().unwrap_or_else(|| to.clone())), 157 + safe(text.as_ref().unwrap_or(to)), 163 158 )); 164 159 } 165 160 166 161 html.push_str(&format!( 167 162 "<p><img src=\"{}\" alt=\"{}\" /></p>\n", 168 163 safe(&href), 169 - safe(&text.clone().unwrap_or_else(|| to.clone())), 164 + safe(text.as_ref().unwrap_or(to)), 170 165 )); 171 166 172 167 continue; ··· 179 174 html.push_str(&format!( 180 175 "<a href=\"{}\">{}</a>", 181 176 href, 182 - safe(&text.clone().unwrap_or_else(|| to.clone())), 177 + safe(text.as_ref().unwrap_or(to)), 183 178 )); 184 179 } 185 180 Node::Heading { level, text } => { ··· 188 183 } 189 184 190 185 if title.is_empty() && *level == 1 { 191 - title = safe(&text.clone()).to_string(); 186 + title = safe(text).to_string(); 192 187 } 193 188 194 189 html.push_str(&format!(
+7 -5
src/response.rs
··· 115 115 let convert_time_taken = timer.elapsed(); 116 116 117 117 if is_raw { 118 - html_context.push_str(&response.content().clone().unwrap_or_default()); 118 + html_context.push_str( 119 + &response.content().as_ref().map_or_else(String::default, String::clone), 120 + ); 119 121 120 122 return Ok( 121 123 HttpResponse::Ok() ··· 265 267 </details></body></html>", 266 268 url, 267 269 response.status(), 268 - i32::from(response.status().clone()), 270 + i32::from(*response.status()), 269 271 response.meta(), 270 272 response_time_taken.as_nanos() as f64 / 1_000_000.0, 271 273 convert_time_taken.as_nanos() as f64 / 1_000_000.0, ··· 278 280 path_matches_pattern(r, req.path()) 279 281 || path_matches_pattern(r, req.path().trim_end_matches('/')) 280 282 }) { 281 - return Ok( 282 - HttpResponse::Ok().body(response.content().clone().unwrap_or_default()), 283 - ); 283 + return Ok(HttpResponse::Ok().body( 284 + response.content().as_ref().map_or_else(String::default, String::clone), 285 + )); 284 286 } 285 287 } 286 288