diff --git a/Cargo.toml b/Cargo.toml index e9407fa..2faab33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hermes" +name = "batflip" version = "0.1.0" edition = "2021" diff --git a/public/assets/main.js b/public/assets/main.js index 1494664..3650871 100644 --- a/public/assets/main.js +++ b/public/assets/main.js @@ -1,2 +1,2 @@ -let body = document.getElementsByTagName('h1'); -console.log(body); +alert("time to rock"); +console.log("hello"); diff --git a/public/assets/style.css b/public/assets/style.css index 8b307dd..519736d 100644 --- a/public/assets/style.css +++ b/public/assets/style.css @@ -1,4 +1,12 @@ body { color: white; background: purple; + max-width: 95%; + display: block; + margin: auto; } + +img { + max-width: 100%; + display: block; +} diff --git a/public/index.html b/public/index.html index f208a8d..89a50b3 100644 --- a/public/index.html +++ b/public/index.html @@ -2,11 +2,11 @@
+
diff --git a/src/connection.rs b/src/connection.rs
index 8047a7e..f2c6824 100644
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -25,24 +25,39 @@ pub fn handle_connection(mut stream: TcpStream) {
.collect();
// Get the first line of the stream which contains request data.
let request_line: String = http_request.first().expect("No request line found").to_string();
- let response: String;
+ let mut response;
// Split the request data on spaces into a vector.
let req_vec: Vec<&str> = request_line.split(" ").collect();
let inc_request = IncomingRequest {
req_type: req_vec[0].to_string(),
path: req_vec[1].to_string(),
};
+
+ // Handle 404.
if inc_request.path.is_empty() {
response = return_response("404");
}
+
+ // Handle images.
+ if inc_request.path.contains("images") {
+ let mut public_route: String = "./public".to_string();
+ public_route.push_str(&inc_request.path);
+ let image_data = fs::read(&public_route).unwrap();
+ let status_line = "HTTP/1.1 200 OK".to_string();
+ let response = format!(
+ "{}\r\nContent-Length: {}\r\n\r\n",
+ status_line,
+ image_data.len()
+ );
+ stream.write(response.as_bytes()).unwrap();
+ stream.write(&image_data).unwrap();
+ }
else {
response = return_response(&inc_request.path);
+ stream.write(response.as_bytes()).unwrap();
}
-
- stream.write_all(response.as_bytes()).unwrap();
}
-
#[allow(dead_code)]
fn get_header(headers: Vec