Respond to TCP Request with 200 OK
Change-Id: Ibed81413b1d7362a66c831a5ef84cb4f74d5d14c
Reviewed-on: https://git.clicks.codes/c/Clicks/BYO/HttpServer/rust/+/246
Tested-by: Skyler Grey <minion@clicks.codes>
Reviewed-by: Skyler Grey <minion@clicks.codes>
diff --git a/.gitignore b/.gitignore
index 8ed082c..4bd756d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,4 +9,4 @@
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
-.direnv/
\ No newline at end of file
+.direnv/
diff --git a/src/main.rs b/src/main.rs
index f85bd02..50cc72e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,17 @@
-use std::net::TcpListener;
+use std::{net::TcpListener, io::Write};
fn main() {
let listener = TcpListener::bind("127.0.0.1:4221").unwrap();
for stream in listener.incoming() {
match stream {
- Ok(_stream) => {
+ Ok(mut _stream) => {
println!("accepted new connection");
+
+ let status = "200 OK\r\n";
+ let res_headers = "\r\n";
+
+ _stream.write(format!("HTTP/1.1 {status}{res_headers}").as_bytes()).unwrap();
}
Err(e) => {
println!("error: {}", e);