Add autoswitch for time field to disable on non-Unix systems to prevent potential crashes.

This commit is contained in:
abbie 2021-12-22 20:38:36 +00:00
parent 3d0f673e19
commit 7ad6eb64b3
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87

View file

@ -199,9 +199,19 @@ fn serve(mut stream: TcpStream) {
let header = "HTTP/1.1 200 OK\r\n";
let content_type = format!("Content-Type: {}\r\n", mime);
let server = "Server: Herb/0.1.4\r\n";
let mut time = format!("Date: {}\r\n", grab_time());
time = time.replace("'","");
let extra_fields = format!("{}{}\r\n", server, time);
let extra_fields;
if cfg!(unix) {
let mut time = format!("Date: {}\r\n", grab_time());
time = time.replace("'","");
extra_fields = format!("{}{}\r\n", server, time);
} else {
// I don't have a Windows or macOS box to test anything on
// which means others are gonna have to deal with it :/
extra_fields = format!("{}\r\n", server);
}
let response = format!("{}{}{}{}", header, content_type, extra_fields, contents);
stream.write(response.as_bytes()).unwrap();