fix data write

This commit is contained in:
yggverse 2025-02-22 06:29:30 +02:00
parent d33c678e3f
commit f62153ac91

View file

@ -72,7 +72,7 @@ fn handle(argument: Arc<Argument>, peer: SocketAddr, stream: &mut TlsStream<TcpS
stream, stream,
|result| match result { |result| match result {
Ok(()) => println!( Ok(()) => println!(
"[{}] [error] [{peer}] Request: {}", "[{}] [info] [{peer}] Request: {}",
now(), now(),
gemini.url gemini.url
), ),
@ -105,10 +105,8 @@ fn handle(argument: Arc<Argument>, peer: SocketAddr, stream: &mut TlsStream<TcpS
), ),
Ok(l) => { Ok(l) => {
data.extend(&input[..l]); data.extend(&input[..l]);
// calculate once // calculate once
let total = data.len(); let total = data.len();
// validate server-side limits // validate server-side limits
if argument.size.is_some_and(|limit| total > limit) { if argument.size.is_some_and(|limit| total > limit) {
const MESSAGE: &str = const MESSAGE: &str =
@ -130,7 +128,6 @@ fn handle(argument: Arc<Argument>, peer: SocketAddr, stream: &mut TlsStream<TcpS
}, },
); );
} }
// all expected data received // all expected data received
if titan.size >= total { if titan.size >= total {
// validate client-side limits // validate client-side limits
@ -157,12 +154,10 @@ fn handle(argument: Arc<Argument>, peer: SocketAddr, stream: &mut TlsStream<TcpS
}, },
); );
} }
// @TODO detect/validate/cache mime based on data received // @TODO detect/validate/cache mime based on data received
// success // success
match storage::Item::create(&argument.directory) { match storage::Item::create(&argument.directory) {
Ok(mut tmp) => match tmp.file.write(titan.data) { Ok(mut tmp) => match tmp.file.write(&data) {
Ok(_) => match tmp.commit() { Ok(_) => match tmp.commit() {
Ok(pmt) => send( Ok(pmt) => send(
&response::redirect::Permanent { &response::redirect::Permanent {