From 9db0750df8b0eed28851cca4b880da2b8ee50bc7 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 3 Jul 2022 05:03:00 +0000 Subject: feat(response): add nocss route --- src/response.rs | 13 +++++++++++++ src/url.rs | 10 ++++++++++ 2 files changed, 23 insertions(+) (limited to 'src') diff --git a/src/response.rs b/src/response.rs index 486ea3e..288a07f 100644 --- a/src/response.rs +++ b/src/response.rs @@ -28,6 +28,7 @@ pub async fn default( ) -> Result { let mut is_proxy = false; let mut is_raw = false; + let mut is_nocss = false; // Try to construct a Gemini URL let url = match make_url( &format!("{}{}", req.path(), { @@ -41,6 +42,7 @@ pub async fn default( false, &mut is_proxy, &mut is_raw, + &mut is_nocss, ) { Ok(url) => url, Err(e) => { @@ -65,6 +67,7 @@ pub async fn default( true, &mut is_proxy, &mut is_raw, + &mut is_nocss, ) { Ok(url) => url, Err(e) => { @@ -123,6 +126,16 @@ pub async fn default( ); } + if is_nocss { + html_context.push_str(&gemini_html.1); + + return Ok( + HttpResponse::Ok() + .content_type(format!("text/html; charset={}", meta.mime())) + .body(html_context), + ); + } + // Try to add an external stylesheet from the `CSS_EXTERNAL` environment // variable. if let Ok(css) = var("CSS_EXTERNAL") { diff --git a/src/url.rs b/src/url.rs index 8c6dd9c..5100d44 100644 --- a/src/url.rs +++ b/src/url.rs @@ -23,6 +23,7 @@ pub fn make( fallback: bool, is_proxy: &mut bool, is_raw: &mut bool, + is_nocss: &mut bool, ) -> Result { Ok( match Url::try_from(&*if path.starts_with("/proxy") { @@ -50,6 +51,15 @@ pub fn make( path.replace("/raw/", ""), if fallback { "/" } else { "" } ) + } else if path.starts_with("/nocss") { + *is_proxy = true; + *is_nocss = true; + + format!( + "gemini://{}{}", + path.replace("/nocss/", ""), + if fallback { "/" } else { "" } + ) } else { // Try to set `ROOT` as `ROOT` environment variable, or use // `"gemini://fuwn.me"` as default. -- cgit v1.2.3