Rename the library
This commit is contained in:
parent
9e2664ec36
commit
40177f03e5
8
Cargo.lock
generated
8
Cargo.lock
generated
|
|
@ -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",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "uhttp"
|
||||
name = "httplz"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
uhttp-ext = { path = "./crates/uhttp-ext" }
|
||||
httplz-ext = { path = "./crates/httplz-ext" }
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# uhttp
|
||||
# httplz
|
||||
|
||||
A small allocation-free, sans-IO HTTP implementation
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "uhttp-ext"
|
||||
name = "httplz-ext"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
uhttp = { path = "../.." }
|
||||
httplz = { path = "../.." }
|
||||
|
|
@ -105,12 +105,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> uhttp::Write for Buf<T, u8>
|
||||
impl<T> httplz::Write for Buf<T, u8>
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
use std::{error::Error, io::Write, net::TcpStream};
|
||||
|
||||
use uhttp::Lift;
|
||||
use httplz::Lift;
|
||||
|
||||
pub fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
|
|
@ -17,21 +17,21 @@ pub fn main() -> Result<(), Box<dyn Error>> {
|
|||
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<dyn Error>> {
|
|||
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<dyn Error>> {
|
|||
Ok(ev) => {
|
||||
println!("{ev}");
|
||||
|
||||
if ev == uhttp::Event::RecvDone {
|
||||
if ev == httplz::Event::RecvDone {
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use std::{error::Error, io::Write, net::TcpListener};
|
||||
|
||||
use uhttp::Lift;
|
||||
use httplz::Lift;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
|
|
@ -18,11 +18,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
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<u8> = 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<dyn Error>> {
|
|||
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<dyn Error>> {
|
|||
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:?}")
|
||||
|
|
|
|||
Loading…
Reference in a new issue