Compare commits
3 Commits
8232bf66ee
...
5df6b9e233
| Author | SHA1 | Date | |
|---|---|---|---|
|
5df6b9e233
|
|||
|
3c5e92a61d
|
|||
|
7edf80da41
|
@@ -0,0 +1 @@
|
|||||||
|
/target/
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "h8r"
|
||||||
|
version = "0.1.0"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "h8r"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# h8r gonna h8
|
||||||
|
|
||||||
|
h + len(ttpserve) + r
|
||||||
|
|
||||||
|
A li'l HTTP server for learning stuff.
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
- [x] server on fixed port responding "oh no"
|
||||||
|
- [ ] configurable port and working directory
|
||||||
|
- [ ] string responses
|
||||||
|
- [ ] error page paths
|
||||||
|
- [ ] serve "index.txt" file if exists, else 404
|
||||||
|
- [ ] serve relative paths with mime type text/plain
|
||||||
|
- [ ] guess mime type
|
||||||
|
- [ ] automatic directory index
|
||||||
|
- [ ] content ranges
|
||||||
|
- [ ] liquid template rendering
|
||||||
|
- [ ] upstream proxy via prefix
|
||||||
|
- [ ] upstream proxy path match
|
||||||
|
- [ ] upstream proxy header middleware rules
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
use std::io::Write;
|
||||||
|
use std::net::{Shutdown, TcpListener};
|
||||||
|
|
||||||
|
fn handle_conn(stream: &mut impl Write) -> std::io::Result<()> {
|
||||||
|
eprintln!("attempting to respond");
|
||||||
|
|
||||||
|
let response = concat![
|
||||||
|
"HTTP/1.1 200 OK\r\n",
|
||||||
|
"content-type: text/plain\r\n",
|
||||||
|
"\r\n",
|
||||||
|
"oh no\n",
|
||||||
|
];
|
||||||
|
|
||||||
|
stream.write_all(response.as_bytes()).unwrap();
|
||||||
|
stream.flush()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
let listener = TcpListener::bind("127.0.0.1:17321").unwrap();
|
||||||
|
|
||||||
|
for stream in listener.incoming() {
|
||||||
|
let mut stream = stream.unwrap();
|
||||||
|
handle_conn(&mut stream)?;
|
||||||
|
stream.shutdown(Shutdown::Both)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn handle_conn_writes_response() {
|
||||||
|
let mut stream = [100u8].repeat(64_000);
|
||||||
|
let _ = handle_conn(&mut stream);
|
||||||
|
assert!(str::from_utf8(&stream).unwrap().contains("oh no"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user