ZOMG IT WERKS

This commit is contained in:
abbie 2021-08-29 16:07:05 +01:00
parent e1f02410ca
commit 2d0ce61654
4 changed files with 67 additions and 8 deletions

39
Cargo.lock generated Normal file
View file

@ -0,0 +1,39 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bytes"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "herb"
version = "0.1.0"
dependencies = [
"http",
]
[[package]]
name = "http"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11"
dependencies = [
"bytes",
"fnv",
"itoa",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"

View file

@ -6,3 +6,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
http = "0.2.4"

View file

@ -6,16 +6,18 @@ This is a little fun experiment for me to mess around with Rust
## Chonklist
I need this stuff to actually have a functioning but basic web server.
[ ] Open a socket
[ ] Recieve HTTP requests
[ ] Process said requests
[ ] Send back HTTP requests
[x] Open a socket
[x] Recieve HTTP requests
[x] Process said requests
[x] Send back HTTP requests
[ ] Read pages from filesystem
### Next Chonklist
The stuff I need to make it usable.
[ ] Read pages from filesystem
[ ] Detect missing files and return 404
[ ] Custom error pages
[ ] User configurable
[ ] Make an actual header
### SUPAR Chonklist
Whatever is on here, just to make it extra spicy.
@ -24,4 +26,3 @@ Whatever is on here, just to make it extra spicy.
[ ] Dynamic pages via CGI?
[ ] Image thumbnailing/compression
[ ] Compressing big files
[ ] Make it user configurable

View file

@ -1,3 +1,21 @@
fn main() {
println!("Hello, world!");
use std::io::{Write};
use std::string;
use std::net::{TcpListener, TcpStream};
fn serve(mut stream: TcpStream) {
let contents = "<h1>herb works!</h1>";
let response = format!("{}{}", "HTTP/1.1 200 OK\r\n\r\n", contents);
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
}
fn main() -> std::io::Result<()> {
let listen = TcpListener::bind("127.0.0.1:8080")?;
for stream in listen.incoming() {
serve(stream?);
}
Ok(())
}