Configurable addr
This commit is contained in:
+2
-1
@@ -1,10 +1,11 @@
|
||||
- [x] server on fixed port responding "oh no"
|
||||
- [ ] configurable port and working directory
|
||||
- [x] configurable addr
|
||||
- [ ] string responses
|
||||
- [ ] error page paths
|
||||
- [ ] serve "index.txt" file if exists, else 404
|
||||
- [ ] serve relative paths with mime type text/plain
|
||||
- [ ] guess mime type
|
||||
- [ ] configurable working directory
|
||||
- [ ] automatic directory index
|
||||
- [ ] content ranges
|
||||
- [ ] liquid template rendering
|
||||
|
||||
+15
-12
@@ -1,6 +1,21 @@
|
||||
use std::io::Write;
|
||||
use std::net::{Shutdown, TcpListener};
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let addr = std::env::var("H8R_ADDR").unwrap_or("127.0.0.1:17321".to_string());
|
||||
let listener = TcpListener::bind(&addr).unwrap();
|
||||
|
||||
eprintln!("h8r: listening at {}", addr);
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let mut stream = stream.unwrap();
|
||||
handle_conn(&mut stream)?;
|
||||
stream.shutdown(Shutdown::Both)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_conn(stream: &mut impl Write) -> std::io::Result<()> {
|
||||
eprintln!("attempting to respond");
|
||||
|
||||
@@ -17,18 +32,6 @@ fn handle_conn(stream: &mut impl Write) -> std::io::Result<()> {
|
||||
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::*;
|
||||
|
||||
Reference in New Issue
Block a user