diff options
author | Teddy Wing | 2020-07-16 00:27:10 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-16 00:27:10 +0200 |
commit | aabde54acf646eaa5d0c4500115ff1805b027d1a (patch) | |
tree | 19ee1c144ca0d07224be7e3a2642bf21f4219ed1 /src/server.rs | |
parent | 0ddfedea3f89f20b100061037277671451b34c4a (diff) | |
download | fastcgi-conduit-aabde54acf646eaa5d0c4500115ff1805b027d1a.tar.bz2 |
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.
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 10 |
1 files changed, 2 insertions, 8 deletions
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<W: Write>(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", |