envrc
This commit is contained in:
parent
27513863cf
commit
9b3151b55d
8 changed files with 2192 additions and 5 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -41,10 +41,11 @@ async fn handle_connection(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_http_connection(
|
||||
mut stream: TcpStream,
|
||||
) -> tokio::io::Result<Option<(WebsocketRead, WebsocketWrite)>> {
|
||||
let mut timeout = 500;
|
||||
let timeout = 50;
|
||||
loop {
|
||||
let req = match time::timeout(
|
||||
Duration::from_millis(timeout),
|
||||
|
|
@ -62,10 +63,7 @@ async fn handle_http_connection(
|
|||
}
|
||||
};
|
||||
|
||||
println!("{req:?}");
|
||||
|
||||
let matchable = req.path.to_matchable();
|
||||
|
||||
let response = match matchable.as_slice() {
|
||||
["public", file] => {
|
||||
match Response::from_file(Path::new(format!("./public/{file}").as_str())) {
|
||||
|
|
@ -91,9 +89,11 @@ async fn handle_http_connection(
|
|||
};
|
||||
response.respond(&mut stream).await?;
|
||||
stream.flush().await?;
|
||||
timeout = 5000;
|
||||
|
||||
if req.headers.contains(&request::RequestHeader::Connection(
|
||||
request::Connection::Close,
|
||||
)) || !req.headers.contains(&request::RequestHeader::Connection(
|
||||
request::Connection::KeepAlive,
|
||||
)) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue