From 874ba0d1f2f5c525e133728e999487064513d714 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 26 Mar 2024 05:30:02 +0000 Subject: feat(response): show redirect content on redirect --- src/response.rs | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'src/response.rs') diff --git a/src/response.rs b/src/response.rs index a6817a2..eea131d 100644 --- a/src/response.rs +++ b/src/response.rs @@ -201,19 +201,51 @@ For example: to proxy "gemini://fuwn.me/uptime", visit "/proxy/fuwn.me/uptime".< germ::request::Status::Success => { html_context.push_str(&gemini_html.1); } - germ::request::Status::PermanentRedirect => { + germ::request::Status::PermanentRedirect + | germ::request::Status::TemporaryRedirect => { html_context.push_str(&format!( - "

This page permanently redirects to {}.

", - response.meta(), - response.meta().trim() - )); - } - germ::request::Status::TemporaryRedirect => { - html_context.push_str(&format!( - "

This page temporarily redirects to {}.

", + "
This page {} redirects to {}.
", + if response.status() == &germ::request::Status::PermanentRedirect { + "permanently" + } else { + "temporarily" + }, response.meta(), response.meta().trim() )); + + let redirect_url = match url_from_path( + response.meta().trim_end_matches('/'), + true, + &mut is_proxy, + &mut is_raw, + &mut is_nocss, + ) { + Ok(url) => url, + Err(e) => { + return Ok( + HttpResponse::BadRequest() + .content_type("text/plain") + .body(format!("{e}")), + ); + } + }; + + html_context.push_str( + &crate::html::from_gemini( + &match germ::request::request(&redirect_url) { + Ok(response) => response, + Err(e) => { + return Ok(HttpResponse::Ok().body(e.to_string())); + } + }, + &redirect_url, + is_proxy, + ) + .unwrap() + .1, + ); } _ => html_context.push_str(&format!("

{}

", response.meta())), } -- cgit v1.2.3