close
Skip to content

Commit 1ca83ae

Browse files
committed
allow receiving more than one packet
1 parent 47b1051 commit 1ca83ae

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎src/protocols/gemini.rs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,24 @@ impl Protocol for Gemini {
206206
let fut = async move {
207207
let mut stream = acceptor.accept(stream).await?;
208208

209-
let mut buffer = [0; 1024];
210-
let n = stream.read(&mut buffer).await?;
211-
let request = String::from_utf8_lossy(&buffer[..n]).to_string();
209+
let mut request = [0; 1026];
210+
let mut len = 0;
211+
loop {
212+
let mut buffer = [0; 1024];
213+
let n = stream.read(&mut buffer).await?;
214+
if n == 0 {
215+
break;
216+
}
217+
// add the new data to the request
218+
request[len..len + n].copy_from_slice(&buffer[..n]);
219+
len += n;
220+
if buffer.contains(&b'\r') || len >= 1024 {
221+
break;
222+
}
223+
}
224+
// ignore everything after the first \r
225+
let request = request[..len].split(|v| v == &b'\r').next().unwrap();
226+
let request = String::from_utf8_lossy(request).to_string();
212227

213228
println!("Gemini request: {request}");
214229

0 commit comments

Comments
 (0)