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
12
src/main.rs
12
src/main.rs
|
@ -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 extra_fields;
|
||||
|
||||
if cfg!(unix) {
|
||||
let mut time = format!("Date: {}\r\n", grab_time());
|
||||
time = time.replace("'","");
|
||||
let extra_fields = format!("{}{}\r\n", server, time);
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue