Add autoswitch for time field to disable on non-Unix systems to prevent potential crashes.
This commit is contained in:
parent
3d0f673e19
commit
7ad6eb64b3
1 changed files with 13 additions and 3 deletions
16
src/main.rs
16
src/main.rs
|
@ -199,9 +199,19 @@ fn serve(mut stream: TcpStream) {
|
||||||
let header = "HTTP/1.1 200 OK\r\n";
|
let header = "HTTP/1.1 200 OK\r\n";
|
||||||
let content_type = format!("Content-Type: {}\r\n", mime);
|
let content_type = format!("Content-Type: {}\r\n", mime);
|
||||||
let server = "Server: Herb/0.1.4\r\n";
|
let server = "Server: Herb/0.1.4\r\n";
|
||||||
let mut time = format!("Date: {}\r\n", grab_time());
|
let extra_fields;
|
||||||
time = time.replace("'","");
|
|
||||||
let extra_fields = format!("{}{}\r\n", server, time);
|
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);
|
let response = format!("{}{}{}{}", header, content_type, extra_fields, contents);
|
||||||
|
|
||||||
stream.write(response.as_bytes()).unwrap();
|
stream.write(response.as_bytes()).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue