♻️ 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.

fix(response): remove hard path fixer

Fuwn a27dd14f 6374a5f6

+39 -79
+39 -79
src/response.rs
··· 57 57 return Ok(HttpResponse::Ok().body(e.to_string())); 58 58 } 59 59 }; 60 + let mut redirect_response_status = None; 61 + let mut redirect_url = None; 60 62 61 - if response.content().is_none() 62 - && response.status() != &germ::request::Status::PermanentRedirect 63 - && response.status() != &germ::request::Status::TemporaryRedirect 63 + if *response.status() == germ::request::Status::PermanentRedirect 64 + || *response.status() == germ::request::Status::TemporaryRedirect 64 65 { 65 - response = match germ::request::request(&match url_from_path( 66 - req.path().trim_end_matches('/'), 67 - true, 68 - &mut is_proxy, 69 - &mut is_raw, 70 - &mut is_nocss, 71 - ) { 72 - Ok(url) => url, 73 - Err(e) => { 74 - return Ok( 75 - HttpResponse::BadRequest() 76 - .content_type("text/plain") 77 - .body(format!("{e}")), 78 - ); 79 - } 80 - }) 81 - .await 82 - { 83 - Ok(response) => response, 84 - Err(e) => { 85 - return Ok(HttpResponse::Ok().body(e.to_string())); 66 + redirect_response_status = Some(*response.status()); 67 + redirect_url = Some( 68 + url::Url::parse(&if response.meta().starts_with('/') { 69 + format!( 70 + "gemini://{}{}", 71 + url.domain().unwrap_or_default(), 72 + response.meta() 73 + ) 74 + } else { 75 + response.meta().to_string() 76 + }) 77 + .unwrap(), 78 + ); 79 + response = 80 + match germ::request::request(&redirect_url.clone().unwrap()).await { 81 + Ok(response) => response, 82 + Err(e) => { 83 + return Ok(HttpResponse::Ok().body(e.to_string())); 84 + } 86 85 } 87 - }; 88 86 } 89 87 90 88 let response_time_taken = timer.elapsed(); ··· 197 195 198 196 match response.status() { 199 197 germ::request::Status::Success => { 200 - html_context.push_str(&gemini_html.1); 201 - } 202 - germ::request::Status::PermanentRedirect 203 - | germ::request::Status::TemporaryRedirect => { 204 - html_context.push_str(&format!( 205 - "<blockquote>This page {} redirects to <a \ 206 - href=\"{}\">{}</a>.</blockquote>", 207 - if response.status() == &germ::request::Status::PermanentRedirect { 208 - "permanently" 209 - } else { 210 - "temporarily" 211 - }, 212 - response.meta(), 213 - response.meta().trim() 214 - )); 215 - 216 - let redirect_url = match url_from_path( 217 - &if response.meta().trim_end_matches('/').starts_with('/') { 218 - format!( 219 - "/proxy/{}{}", 220 - url.domain().unwrap_or_default(), 221 - response.meta().trim_end_matches('/') 222 - ) 223 - } else { 224 - response.meta().trim_end_matches('/').to_string() 225 - }, 226 - false, 227 - &mut is_proxy, 228 - &mut is_raw, 229 - &mut is_nocss, 230 - ) { 231 - Ok(url) => url, 232 - Err(e) => { 233 - return Ok( 234 - HttpResponse::BadRequest() 235 - .content_type("text/plain") 236 - .body(format!("{e}")), 237 - ); 238 - } 239 - }; 198 + if let (Some(status), Some(url)) = 199 + (redirect_response_status, redirect_url) 200 + { 201 + html_context.push_str(&format!( 202 + "<blockquote>This page {} redirects to <a \ 203 + href=\"{}\">{}</a>.</blockquote>", 204 + if status == germ::request::Status::PermanentRedirect { 205 + "permanently" 206 + } else { 207 + "temporarily" 208 + }, 209 + url, 210 + url 211 + )); 212 + } 240 213 241 - html_context.push_str( 242 - &crate::html::from_gemini( 243 - &match germ::request::request(&redirect_url).await { 244 - Ok(response) => response, 245 - Err(e) => { 246 - return Ok(HttpResponse::Ok().body(e.to_string())); 247 - } 248 - }, 249 - &redirect_url, 250 - is_proxy, 251 - ) 252 - .unwrap() 253 - .1, 254 - ); 214 + html_context.push_str(&gemini_html.1); 255 215 } 256 216 _ => html_context.push_str(&format!("<p>{}</p>", response.meta())), 257 217 }