From aabde54acf646eaa5d0c4500115ff1805b027d1a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 16 Jul 2020 00:27:10 +0200 Subject: server.rs: Fix HTTP status code header I was getting persistent 500 errors on Apache with mod_fastcgi: FastCGI: comm with server "/Applications/MAMP/htdocs/test.fcgi" aborted: error parsing headers: malformed header 'HTTP/1.1 200 OK' Forgot that you need to use a "Status" header for FastCGI to set the HTTP status code, like: Status: 404 This isn't an HTTP server. Apparently knew this at one point for the DomeKey web site, but completely forgot. Thanks to Ole (https://stackoverflow.com/users/312098/ole) and RichieHindle (https://stackoverflow.com/users/21886/richiehindle) on Stack Overflow for this question and answer that helped me figure it out: https://stackoverflow.com/questions/11223166/malformed-header-from-script-bad-header-http-1-1-302-found Didn't notice this previously as I was using Lighttpd for testing, and its FastCGI module must be more forgiving. --- src/server.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/server.rs') diff --git a/src/server.rs b/src/server.rs index d74aa78..d23ab9d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -27,10 +27,6 @@ use snafu::{ResultExt, Snafu}; use crate::request; -/// The HTTP version used by the server. -const HTTP_VERSION: &'static str = "HTTP/1.1"; - - /// Wraps server errors. #[derive(Debug, Snafu)] pub enum Error { @@ -109,8 +105,7 @@ where H: Handler + 'static + Sync write!( &mut stdout, - "{} {} {}\r\n", - HTTP_VERSION, + "Status: {} {}\r\n", head.status.as_str(), head.status.canonical_reason().unwrap_or("UNKNOWN"), )?; @@ -141,8 +136,7 @@ fn internal_server_error(mut w: W) { write!( w, - "{} {} {}\r\n{}\r\n\r\n", - HTTP_VERSION, + "Status: {} {}\r\n{}\r\n\r\n", code, code.canonical_reason().unwrap_or_default(), "Content-Length: 0", -- cgit v1.2.3