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
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uhttp"
|
name = "httplz"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"uhttp-ext",
|
"httplz-ext",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uhttp-ext"
|
name = "httplz-ext"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"uhttp",
|
"httplz",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
name = "uhttp"
|
name = "httplz"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
[dev-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
|
A small allocation-free, sans-IO HTTP implementation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "uhttp-ext"
|
name = "httplz-ext"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[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
|
where
|
||||||
T: AsRef<[u8]> + AsMut<[u8]>,
|
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)
|
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 std::{error::Error, io::Write, net::TcpStream};
|
||||||
|
|
||||||
use uhttp::Lift;
|
use httplz::Lift;
|
||||||
|
|
||||||
pub fn main() -> Result<(), Box<dyn Error>> {
|
pub fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let mut args = std::env::args().skip(1);
|
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 mut stream = TcpStream::connect((host.as_str(), port.parse()?))?;
|
||||||
|
|
||||||
let buf = vec![0; 4096];
|
let buf = vec![0; 4096];
|
||||||
let mut buf = uhttp_ext::Buf::new(buf);
|
let mut buf = httplz_ext::Buf::new(buf);
|
||||||
let mut conn = uhttp::Connection::new(uhttp::Role::Client);
|
let mut conn = httplz::Connection::new(httplz::Role::Client);
|
||||||
let events = &[
|
let events = &[
|
||||||
uhttp::RequestLine {
|
httplz::RequestLine {
|
||||||
version: uhttp::Version::HTTP1_1,
|
version: httplz::Version::HTTP1_1,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
target: &path,
|
target: &path,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
uhttp::HeaderOther::from(("Host", host.as_bytes())).into(),
|
httplz::HeaderOther::from(("Host", host.as_bytes())).into(),
|
||||||
uhttp::HeaderOther::from(("Accept", "*/*")).into(),
|
httplz::HeaderOther::from(("Accept", "*/*")).into(),
|
||||||
uhttp::HeaderSpecial::ContentLength(data.len()).into(),
|
httplz::HeaderSpecial::ContentLength(data.len()).into(),
|
||||||
uhttp::Event::HeadersDone,
|
httplz::Event::HeadersDone,
|
||||||
uhttp::Event::BodyChunk(data.as_bytes()),
|
httplz::Event::BodyChunk(data.as_bytes()),
|
||||||
uhttp::Event::SendDone,
|
httplz::Event::SendDone,
|
||||||
];
|
];
|
||||||
|
|
||||||
for event in events {
|
for event in events {
|
||||||
|
|
@ -47,8 +47,8 @@ pub fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let (d, r) = conn.handle_recv(data).lift();
|
let (d, r) = conn.handle_recv(data).lift();
|
||||||
|
|
||||||
match r {
|
match r {
|
||||||
Err(uhttp::Error {
|
Err(httplz::Error {
|
||||||
kind: uhttp::ErrorKind::NeedMoreData,
|
kind: httplz::ErrorKind::NeedMoreData,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
buf.read_from(&mut stream)?;
|
buf.read_from(&mut stream)?;
|
||||||
|
|
@ -58,7 +58,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Ok(ev) => {
|
Ok(ev) => {
|
||||||
println!("{ev}");
|
println!("{ev}");
|
||||||
|
|
||||||
if ev == uhttp::Event::RecvDone {
|
if ev == httplz::Event::RecvDone {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use std::{error::Error, io::Write, net::TcpListener};
|
use std::{error::Error, io::Write, net::TcpListener};
|
||||||
|
|
||||||
use uhttp::Lift;
|
use httplz::Lift;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let mut args = std::env::args().skip(1);
|
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()?))?;
|
let listener = TcpListener::bind((host, port.parse()?))?;
|
||||||
loop {
|
loop {
|
||||||
let (mut stream, _) = listener.accept()?;
|
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 body: Vec<u8> = Vec::new();
|
||||||
let mut buf = vec![0; 1024].into_boxed_slice();
|
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;
|
let mut method_not_allowed = false;
|
||||||
|
|
||||||
|
|
@ -30,20 +30,20 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let data = buf.filled();
|
let data = buf.filled();
|
||||||
let (remaining, r) = conn.handle_recv(data).lift();
|
let (remaining, r) = conn.handle_recv(data).lift();
|
||||||
match r.map_err(|e| e.kind) {
|
match r.map_err(|e| e.kind) {
|
||||||
Err(uhttp::ErrorKind::NeedMoreData) => {
|
Err(httplz::ErrorKind::NeedMoreData) => {
|
||||||
buf.read_from(&mut stream)?;
|
buf.read_from(&mut stream)?;
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Err(e) => panic!("{e:?}"),
|
Err(e) => panic!("{e:?}"),
|
||||||
Ok(event) => {
|
Ok(event) => {
|
||||||
match event {
|
match event {
|
||||||
uhttp::Event::RequestLine(r) => {
|
httplz::Event::RequestLine(r) => {
|
||||||
if !r.method.eq_ignore_ascii_case("post") {
|
if !r.method.eq_ignore_ascii_case("post") {
|
||||||
method_not_allowed = true;
|
method_not_allowed = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
uhttp::Event::RecvDone => break,
|
httplz::Event::RecvDone => break,
|
||||||
uhttp::Event::BodyChunk(b) => body.extend_from_slice(b),
|
httplz::Event::BodyChunk(b) => body.extend_from_slice(b),
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -53,34 +53,34 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
buf.pop_front(len);
|
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 {
|
httplz::Event::StatusLine(httplz::StatusLine {
|
||||||
version: uhttp::Version::HTTP1_1,
|
version: httplz::Version::HTTP1_1,
|
||||||
status_code: 405,
|
status_code: 405,
|
||||||
status_text: "Method not allowed",
|
status_text: "Method not allowed",
|
||||||
}),
|
}),
|
||||||
uhttp::Event::HeadersDone,
|
httplz::Event::HeadersDone,
|
||||||
uhttp::Event::SendDone,
|
httplz::Event::SendDone,
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
&[
|
&[
|
||||||
uhttp::Event::StatusLine(uhttp::StatusLine {
|
httplz::Event::StatusLine(httplz::StatusLine {
|
||||||
version: uhttp::Version::HTTP1_1,
|
version: httplz::Version::HTTP1_1,
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
status_text: "OK",
|
status_text: "OK",
|
||||||
}),
|
}),
|
||||||
uhttp::Event::Header(uhttp::Header::Special(
|
httplz::Event::Header(httplz::Header::Special(
|
||||||
uhttp::HeaderSpecial::ContentLength(body.len()),
|
httplz::HeaderSpecial::ContentLength(body.len()),
|
||||||
)),
|
)),
|
||||||
uhttp::Event::HeadersDone,
|
httplz::Event::HeadersDone,
|
||||||
uhttp::Event::BodyChunk(body.as_slice()),
|
httplz::Event::BodyChunk(body.as_slice()),
|
||||||
uhttp::Event::SendDone,
|
httplz::Event::SendDone,
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
let buf = vec![0; 1024];
|
let buf = vec![0; 1024];
|
||||||
let mut cursor = uhttp::WriteCursor::new(buf);
|
let mut cursor = httplz::WriteCursor::new(buf);
|
||||||
for p in parts {
|
for p in parts {
|
||||||
if let Err(e) = conn.handle_send(p, &mut cursor) {
|
if let Err(e) = conn.handle_send(p, &mut cursor) {
|
||||||
panic!("{e:?}")
|
panic!("{e:?}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue