diff --git a/Cargo.toml b/Cargo.toml index a907534..8d39d9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "september" -version = "0.2.12" +version = "0.2.13" authors = ["Fuwn "] edition = "2021" description = "A simple and efficient Gemini-to-HTTP proxy." 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())), }