Skip to content

Commit c902f2f

Browse files
bors[bot]stlankes
andauthored
Merge #393
393: improve output message of httpd r=mkroening a=stlankes - use the time crate to determine the current UTC time - return greeting with a current timestamp Co-authored-by: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
2 parents 951b163 + 4e2e7c0 commit c902f2f

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

examples/httpd/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ publish = false
88
[dependencies]
99
tiny_http = "0.12"
1010

11+
[dependencies.time]
12+
version = "0.3"
13+
1114
[target.'cfg(target_os = "hermit")'.dependencies.hermit-sys]
1215
path = "../../hermit-sys"
1316
default-features = false

examples/httpd/src/main.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ use hermit_sys as _;
55

66
fn main() {
77
let crab = vec![0xF0_u8, 0x9F_u8, 0xA6_u8, 0x80_u8];
8-
let text = format!(
9-
"Hello from RustyHermit {}",
10-
String::from_utf8(crab).unwrap_or_default()
11-
);
128

139
let server = tiny_http::Server::http("0.0.0.0:9975").unwrap();
1410
println!("Now listening on port 9975");
@@ -24,7 +20,13 @@ fn main() {
2420
request.headers()
2521
);
2622

27-
let response = tiny_http::Response::from_string(text.clone());
23+
let now = time::OffsetDateTime::now_utc();
24+
let text = format!(
25+
"Hello from RustyHermit {}!\nThe current UTC time is {}!\n",
26+
String::from_utf8(crab.clone()).unwrap_or_default(),
27+
now
28+
);
29+
let response = tiny_http::Response::from_string(text);
2830
request.respond(response).expect("Responded");
2931
}
3032

@@ -37,7 +39,13 @@ fn main() {
3739
request.headers()
3840
);
3941

40-
let response = tiny_http::Response::from_string(text.clone());
42+
let now = time::OffsetDateTime::now_utc();
43+
let text = format!(
44+
"Hello from RustyHermit {}!\nThe current UTC time is {}!\n",
45+
String::from_utf8(crab.clone()).unwrap_or_default(),
46+
now
47+
);
48+
let response = tiny_http::Response::from_string(text);
4149
request.respond(response).expect("Responded");
4250
}
4351
}

0 commit comments

Comments
 (0)