From 40177f03e5e600f415db979b17e2ecd84a4af92b Mon Sep 17 00:00:00 2001 From: soup Date: Mon, 14 Oct 2024 23:49:23 -0400 Subject: [PATCH] Rename the library --- Cargo.lock | 8 ++--- Cargo.toml | 4 +-- README.md | 2 +- crates/{uhttp-ext => httplz-ext}/Cargo.toml | 4 +-- crates/{uhttp-ext => httplz-ext}/src/lib.rs | 6 ++-- examples/client.rs | 28 +++++++-------- examples/echo.rs | 40 ++++++++++----------- 7 files changed, 46 insertions(+), 46 deletions(-) rename crates/{uhttp-ext => httplz-ext}/Cargo.toml (55%) rename crates/{uhttp-ext => httplz-ext}/src/lib.rs (93%) diff --git a/Cargo.lock b/Cargo.lock index 46b4827..01b3893 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,15 +3,15 @@ version = 3 [[package]] -name = "uhttp" +name = "httplz" version = "0.1.0" dependencies = [ - "uhttp-ext", + "httplz-ext", ] [[package]] -name = "uhttp-ext" +name = "httplz-ext" version = "0.1.0" dependencies = [ - "uhttp", + "httplz", ] diff --git a/Cargo.toml b/Cargo.toml index 4a4bb87..e39e36f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "uhttp" +name = "httplz" version = "0.1.0" edition = "2021" [dependencies] [dev-dependencies] -uhttp-ext = { path = "./crates/uhttp-ext" } \ No newline at end of file +httplz-ext = { path = "./crates/httplz-ext" } \ No newline at end of file diff --git a/README.md b/README.md index fd638f6..4ef85f2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# uhttp +# httplz A small allocation-free, sans-IO HTTP implementation diff --git a/crates/uhttp-ext/Cargo.toml b/crates/httplz-ext/Cargo.toml similarity index 55% rename from crates/uhttp-ext/Cargo.toml rename to crates/httplz-ext/Cargo.toml index 5bdf4e4..ef51d96 100644 --- a/crates/uhttp-ext/Cargo.toml +++ b/crates/httplz-ext/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "uhttp-ext" +name = "httplz-ext" version = "0.1.0" edition = "2021" [dependencies] -uhttp = { path = "../.." } +httplz = { path = "../.." } diff --git a/crates/uhttp-ext/src/lib.rs b/crates/httplz-ext/src/lib.rs similarity index 93% rename from crates/uhttp-ext/src/lib.rs rename to crates/httplz-ext/src/lib.rs index da573bf..490b844 100644 --- a/crates/uhttp-ext/src/lib.rs +++ b/crates/httplz-ext/src/lib.rs @@ -105,12 +105,12 @@ where } } -impl uhttp::Write for Buf +impl httplz::Write for Buf where T: AsRef<[u8]> + AsMut<[u8]>, { - fn write(&mut self, buf: &[u8]) -> uhttp::Written { + fn write(&mut self, buf: &[u8]) -> httplz::Written { self.extend_from_slice(buf) - .map_err(|_| uhttp::ErrorKind::BufNotBigEnough.into()) + .map_err(|_| httplz::ErrorKind::BufNotBigEnough.into()) } } diff --git a/examples/client.rs b/examples/client.rs index 6635194..41111f1 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -5,7 +5,7 @@ use std::{error::Error, io::Write, net::TcpStream}; -use uhttp::Lift; +use httplz::Lift; pub fn main() -> Result<(), Box> { let mut args = std::env::args().skip(1); @@ -17,21 +17,21 @@ pub fn main() -> Result<(), Box> { let mut stream = TcpStream::connect((host.as_str(), port.parse()?))?; let buf = vec![0; 4096]; - let mut buf = uhttp_ext::Buf::new(buf); - let mut conn = uhttp::Connection::new(uhttp::Role::Client); + let mut buf = httplz_ext::Buf::new(buf); + let mut conn = httplz::Connection::new(httplz::Role::Client); let events = &[ - uhttp::RequestLine { - version: uhttp::Version::HTTP1_1, + httplz::RequestLine { + version: httplz::Version::HTTP1_1, method: "POST", target: &path, } .into(), - uhttp::HeaderOther::from(("Host", host.as_bytes())).into(), - uhttp::HeaderOther::from(("Accept", "*/*")).into(), - uhttp::HeaderSpecial::ContentLength(data.len()).into(), - uhttp::Event::HeadersDone, - uhttp::Event::BodyChunk(data.as_bytes()), - uhttp::Event::SendDone, + httplz::HeaderOther::from(("Host", host.as_bytes())).into(), + httplz::HeaderOther::from(("Accept", "*/*")).into(), + httplz::HeaderSpecial::ContentLength(data.len()).into(), + httplz::Event::HeadersDone, + httplz::Event::BodyChunk(data.as_bytes()), + httplz::Event::SendDone, ]; for event in events { @@ -47,8 +47,8 @@ pub fn main() -> Result<(), Box> { let (d, r) = conn.handle_recv(data).lift(); match r { - Err(uhttp::Error { - kind: uhttp::ErrorKind::NeedMoreData, + Err(httplz::Error { + kind: httplz::ErrorKind::NeedMoreData, .. }) => { buf.read_from(&mut stream)?; @@ -58,7 +58,7 @@ pub fn main() -> Result<(), Box> { Ok(ev) => { println!("{ev}"); - if ev == uhttp::Event::RecvDone { + if ev == httplz::Event::RecvDone { break; } }, diff --git a/examples/echo.rs b/examples/echo.rs index 9f36514..3cd5b19 100644 --- a/examples/echo.rs +++ b/examples/echo.rs @@ -6,7 +6,7 @@ use std::{error::Error, io::Write, net::TcpListener}; -use uhttp::Lift; +use httplz::Lift; fn main() -> Result<(), Box> { let mut args = std::env::args().skip(1); @@ -18,11 +18,11 @@ fn main() -> Result<(), Box> { let listener = TcpListener::bind((host, port.parse()?))?; loop { let (mut stream, _) = listener.accept()?; - let mut conn = uhttp::Connection::new(uhttp::Role::Server); + let mut conn = httplz::Connection::new(httplz::Role::Server); let mut body: Vec = Vec::new(); let mut buf = vec![0; 1024].into_boxed_slice(); - let mut buf = uhttp_ext::Buf::new(&mut buf); + let mut buf = httplz_ext::Buf::new(&mut buf); let mut method_not_allowed = false; @@ -30,20 +30,20 @@ fn main() -> Result<(), Box> { let data = buf.filled(); let (remaining, r) = conn.handle_recv(data).lift(); match r.map_err(|e| e.kind) { - Err(uhttp::ErrorKind::NeedMoreData) => { + Err(httplz::ErrorKind::NeedMoreData) => { buf.read_from(&mut stream)?; continue; }, Err(e) => panic!("{e:?}"), Ok(event) => { match event { - uhttp::Event::RequestLine(r) => { + httplz::Event::RequestLine(r) => { if !r.method.eq_ignore_ascii_case("post") { method_not_allowed = true; } }, - uhttp::Event::RecvDone => break, - uhttp::Event::BodyChunk(b) => body.extend_from_slice(b), + httplz::Event::RecvDone => break, + httplz::Event::BodyChunk(b) => body.extend_from_slice(b), _ => (), }; }, @@ -53,34 +53,34 @@ fn main() -> Result<(), Box> { buf.pop_front(len); } - let parts: &[uhttp::Event] = if method_not_allowed { + let parts: &[httplz::Event] = if method_not_allowed { &[ - uhttp::Event::StatusLine(uhttp::StatusLine { - version: uhttp::Version::HTTP1_1, + httplz::Event::StatusLine(httplz::StatusLine { + version: httplz::Version::HTTP1_1, status_code: 405, status_text: "Method not allowed", }), - uhttp::Event::HeadersDone, - uhttp::Event::SendDone, + httplz::Event::HeadersDone, + httplz::Event::SendDone, ] } else { &[ - uhttp::Event::StatusLine(uhttp::StatusLine { - version: uhttp::Version::HTTP1_1, + httplz::Event::StatusLine(httplz::StatusLine { + version: httplz::Version::HTTP1_1, status_code: 200, status_text: "OK", }), - uhttp::Event::Header(uhttp::Header::Special( - uhttp::HeaderSpecial::ContentLength(body.len()), + httplz::Event::Header(httplz::Header::Special( + httplz::HeaderSpecial::ContentLength(body.len()), )), - uhttp::Event::HeadersDone, - uhttp::Event::BodyChunk(body.as_slice()), - uhttp::Event::SendDone, + httplz::Event::HeadersDone, + httplz::Event::BodyChunk(body.as_slice()), + httplz::Event::SendDone, ] }; let buf = vec![0; 1024]; - let mut cursor = uhttp::WriteCursor::new(buf); + let mut cursor = httplz::WriteCursor::new(buf); for p in parts { if let Err(e) = conn.handle_send(p, &mut cursor) { panic!("{e:?}")