aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCeleste <colean@colean.cc>2021-12-22 20:38:36 +0000
committerCeleste <colean@colean.cc>2021-12-22 20:38:36 +0000
commit7ad6eb64b320e62a1a0510b85a8647f066e6d7d1 (patch)
treee94087a4a8694945ada072101f4c33f337073ea3
parent3d0f673e199fc05e88e083e8a67dc578de52293e (diff)
Add autoswitch for time field to disable on non-Unix systems to prevent potential crashes.
-rw-r--r--src/main.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 5b36d12..5e7442a 100644
--- a/src/main.rs
+++ b/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 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();