diff options
author | gennyble <gen@nyble.dev> | 2025-03-11 19:16:29 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2025-03-11 19:16:29 -0500 |
commit | c98eca9a85c3226acaee7cdfa766a0e7550853e2 (patch) | |
tree | 4885c72b883c7e3f91477350e65eadf9352e8458 | |
parent | 67e7e572e814b1cfcb1580d19a419a1785a2a9ae (diff) | |
download | corgi-c98eca9a85c3226acaee7cdfa766a0e7550853e2.tar.gz corgi-c98eca9a85c3226acaee7cdfa766a0e7550853e2.zip |
fix infinite loop and dewarn
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs index 494214e..da021a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,14 @@ -use core::panic; use std::{ net::{IpAddr, SocketAddr}, pin::Pin, - str::FromStr, }; use confindent::Confindent; use http_body_util::{BodyExt, Full}; use hyper::{ HeaderMap, Request, Response, StatusCode, - body::{Body, Bytes, Incoming}, - header::{HeaderName, HeaderValue, LAST_MODIFIED}, + body::{Bytes, Incoming}, + header::HeaderValue, server::conn::http1, service::Service, }; @@ -45,6 +43,7 @@ fn main() { rt.block_on(async { run(settings).await }); } +// We have tokio::main at home :) async fn run(settings: Settings) { let addr = SocketAddr::from(([0, 0, 0, 0], settings.port)); let listen = TcpListener::bind(addr).await.unwrap(); @@ -77,12 +76,9 @@ impl Service<Request<Incoming>> for Svc { type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>; fn call(&self, req: Request<Incoming>) -> Self::Future { - fn make<B: Into<Bytes>>(b: B) -> Result<Response<Full<Bytes>>, hyper::Error> { - Ok(Response::builder().body(Full::new(b.into())).unwrap()) - } - let settings = self.settings.clone(); let caddr = self.client_addr; + Box::pin(async move { Ok(Self::handle(settings, caddr, req).await) }) } } @@ -210,6 +206,7 @@ impl Svc { let value = &line[colon + 1..]; response.headers.push((key.to_vec(), value.to_vec())); + // Is this header a status line? let key_string = String::from_utf8_lossy(key); if key_string == "Status" { let value_string = String::from_utf8_lossy(value); @@ -219,18 +216,19 @@ impl Svc { } } - // Body next + // Body next? if curr[nl + 1] == b'\n' || (curr[nl + 1] == b'\r' && curr[nl + 2] == b'\n') { let body = &curr[nl + 2..]; if body.len() > 0 { response.body = Some(body.to_vec()); } - } else { - curr = &curr[nl + 1..]; + + return response; } - } - response + // Move past the newline + curr = &curr[nl + 1..]; + } } } |