Fix bug where autorewrite was always on, respond 50 and log instead of panic on rewrite error

This commit is contained in:
Emi Tatsuo 2020-12-05 11:05:04 -05:00
parent 680c04abe4
commit 9bc1f317c5
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B

View file

@ -390,6 +390,7 @@ impl ServerInner {
request.set_cert(client_cert); 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) { let mut response = if let Some((trailing, handler)) = self.routes.match_request(&request) {
request.set_trailing(trailing); request.set_trailing(trailing);
handler.handle(request.clone()).await handler.handle(request.clone()).await
@ -397,14 +398,27 @@ impl ServerInner {
Response::not_found() Response::not_found()
}; };
#[cfg(feature = "scgi_srv")] // No point running noop code
if self.autorewrite {
match response.rewrite_all(&request).await { match response.rewrite_all(&request).await {
Ok(true) => { /* all is well */ } Ok(true) => { /* all is well */ }
Ok(false) => panic!("Upstream did not include SCRIPT_PATH or SCRIPT_NAME"), 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) => { Err(e) => {
error!("Error reading text/gemini file from Response reader: {}", e); error!("Error reading text/gemini file from Response reader: {}", e);
response = Response::not_found(); response = Response::not_found();
} }
} }
}
self.send_response(response, &mut stream).await self.send_response(response, &mut stream).await
.context("Failed to send response")?; .context("Failed to send response")?;