diff --git a/src/lib.rs b/src/lib.rs index 7f2dd10..b61acbf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -390,6 +390,7 @@ impl ServerInner { request.set_cert(client_cert); } + #[cfg_attr(feature = "gemini_srv", allow(unused_mut))] // Used for scgi_srv only let mut response = if let Some((trailing, handler)) = self.routes.match_request(&request) { request.set_trailing(trailing); handler.handle(request.clone()).await @@ -397,12 +398,25 @@ impl ServerInner { Response::not_found() }; - match response.rewrite_all(&request).await { - Ok(true) => { /* all is well */ } - Ok(false) => panic!("Upstream did not include SCRIPT_PATH or SCRIPT_NAME"), - Err(e) => { - error!("Error reading text/gemini file from Response reader: {}", e); - response = Response::not_found(); + #[cfg(feature = "scgi_srv")] // No point running noop code + if self.autorewrite { + match response.rewrite_all(&request).await { + Ok(true) => { /* all is well */ } + Ok(false) => { + error!( + concat!( + "Upstream did not include SCRIPT_PATH or SCRIPT_NAME, refusing to", + " serve any text/gemini content with absolute links. It's most", + " likely that the proxy server you're using doesn't correctly", + " or completely implement the SCGI specification.", + ) + ); + response = Response::temporary_failure("Server misconfigured"); + }, + Err(e) => { + error!("Error reading text/gemini file from Response reader: {}", e); + response = Response::not_found(); + } } }